You are here: Re: foreach - Array « PHP Programming Language « IT news, forums, messages
Re: foreach - Array

Posted by Alan Little on 05/30/06 20:19

Carved in mystic runes upon the very living rock, the last words of David
Haynes of comp.lang.php make plain:

> iavian wrote:
>> hi
>>
>> i want to modify an array in foreach loop
>>
>> foreach($array as $ele){
>> $ele = $some_random_string;
>> }
>>
>> i should see here the modified $array .
>>
>> thnaks in advance
>>
> foreach( $array as &$ele ) {
> $ele = $some_random_string;
> }
>
> should work as you want it to.

Only in PHP5.

http://us3.php.net/manual/en/control-structures.foreach.php

"Unless the array is referenced, foreach operates on a copy of the
specified array and not the array itself....As of PHP 5, you can easily
modify array's elements by preceding $value with &. This will assign
reference instead of copying the value."

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/

 

Navigation:

[Reply to this 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

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