You are here: Re: php bug? « PHP Programming Language « IT news, forums, messages
Re: php bug?

Posted by Chung Leong on 12/11/05 19:23

Chameleon wrote:
> It is a php bug or a my bug?

It's your bug I suspect. The problem can't be reproduced with the code
as given. If you move the var_dump($a) to the end, then you see it.

<?

$a = array(array(1, 2), array(2, 3), array(4, 5));
$b = array(6, 7, 8);

foreach($a as & $v)
$v = array_merge($v, $b);

foreach($a as $v)
var_dump($v);

var_dump($a);

?>

The second foreach() is setting the value of $v to each element in $a.
At this point, $v is still pointing to the last element in $a,
resulting from the first foreach(). The last element in $a is thus is
set repeatedly to all elements preceding it.

It's a good idea to unset() references when they're no longer needed to
avoid unintended modification later on.

 

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

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