Re: Associative array question

From: Date: Sun, 30 May 2004 17:51:18 +0000
Subject: Re: Associative array question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-187237@lists.php.net to get a copy of this message
csnm@ns.sympatico.ca wrote:
Hello, If I have an associative array like: $myFriendsAges['Tom']=25; $myFriendsAges['Bill']=35; $myFriendsAges['Al']=45; $myFriendsAges['Mark']=55; Is there a way to index name into a string. I would like to be able to echo something like: My friend Bill is 35 years of age. Is there a way to do this?
No sure what you mean... but it is possible this way: <?php foreach($myFriendsAges as $name=>$age) { echo "My friend ".$name." is ".$age." years of age.<br>\n"; } ?> -- Johan Holst Nielsen Freelance PHP Developer http://phpgeek.dk

« previous php.general (#187237) next »