|
Posted by john on 10/03/40 11:21
I want do walk through an array of objects and update the objects'
attributes. I thought I could do it using foreach, but it doesn't work! It
appears that foreach work on a copy of the array, not the actual array.
// Try to update
foreach ($people as $person)
$person->age++;
// Print
foreach ($people as $person)
echo $person->name." is ".$person->age." years old.<br />";
What's the right way to do this? I'm using PHP 4.3.0. Thanks.
-John
johnbkim@myfastELEPHANTmail.com
(remove the pachyderm)
Navigation:
[Reply to this message]
|