Array function problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asif_phpdn
Forum Commoner
Posts: 28
Joined: Sun Aug 26, 2007 8:50 pm

Array function problem

Post 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. :(
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Read the manual closely for array_values() and look carefully at the example.
lnt
Forum Newbie
Posts: 12
Joined: Mon Sep 24, 2007 8:47 am

Post by lnt »

Code: Select all

print_r(array_values($menu));
or

Code: Select all

var_dump(array_values($menu));
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post 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>';
}
Post Reply