Reply to Can you do foreach by reference?

Your name:

Reply:


Posted by john on 10/10/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)

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация