i have following function where i have brands info in an array. i should get array containing those info when i pass brand name to this function.
function brand_info($brand)
{
$brands_list=array (
'lg'=>
array(
'name' => 'LG Phone Company',
'country' => 'country',
'founded_year' => '2001'
),
'nokia'=>
array(
'name' => 'Nokia Phone Company',
'country' => 'country',
'founded_year' => '2001'
)
);
if(in_array($brand,$brands_list))
{
// return array containg company info
}
}
this should return an array by which i can show these info.
$brand_info=brand_info($brand_name);
echo $brand_info['name'];
what may be the best way to do this?
return $brands_list[$brand];? Apparently you already know how to work with arrays, so what is the problem?in_arraytests whether the value exists in the array. You are testing for a key, so it should beif(isset($brands_list[$brand])).