Re: [PHP] emulation of foreach with reference

2002-03-07 Thread Andrey Hristov
ooops On Thursday 07 March 2002 09:09 pm, Andrey Hristov wrote: > try this: > echo "foo".$i++; > echo "\n"; > echo "bar".($+++0); > ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] emulation of foreach with reference

2002-03-07 Thread Andrey Hristov
try this: Thanks for showing that I add new element to the array. This is because on last iteration $k is null and I access $ar[$k] which automatically adds the new element. Why? I don't know? Maybe because I refer it by reference! The fixed code is This will not add new element to the arra

[PHP] emulation of foreach with reference

2002-03-07 Thread Andrey Hristov
The code below is too weird. I spent 15 min writing it but now works: for(reset($ar),list($k,)=each($ar),$v=&$ar[$k];$k;list($k,)=each($ar),$v=&$ar[$k]){ var_dump($k,$v); $v='ather'.($j+++0); var_dump($k,$v); } The $ar array is generated in