Page 1 of 1

Array function problem

Posted: Sat Sep 29, 2007 12:12 am
by asif_phpdn
I'm facing a problem with array functions.

Code: Select all

$menu=array('breakfast' => 'butter and bread','lunch' =>'normal','dinner' =>'dish and salad');

echo is_array($menu);
echo "<br>";
echo array_values($menu);
the problem is array_values() function return just "Array" but not the values. I can't understand the problem. :(

Posted: Sat Sep 29, 2007 12:37 am
by RobertGonzalez
Read the manual closely for array_values() and look carefully at the example.

Posted: Sat Sep 29, 2007 12:47 am
by lnt

Code: Select all

print_r(array_values($menu));
or

Code: Select all

var_dump(array_values($menu));

Posted: Sat Sep 29, 2007 1:15 am
by s.dot
Either/or.

Most likely you'll want to assign the array_values($menu) to a variable. And then loop through the values with a foreach() statement.

Posted: Sat Sep 29, 2007 1:47 am
by amir

Code: Select all

$menu = array('breakfast' => 'butter and bread','lunch' =>'normal','dinner' =>'dish and salad');
foreach($menu as $key => $value) {
	echo $key.'______________________'.$value.'<br>';
}