note 6546 deleted from control-structures.foreach by sniper

From: Date: Tue, 10 Jun 2003 22:54:26 +0000
Subject: note 6546 deleted from control-structures.foreach by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-50139@lists.php.net to get a copy of this message
Note Submitter: evaugh@iname.com ---- For things like sorting algorithms, this doesn't work: foreach ($array as $n) { foreach ($array as $n2) { ... } } It will do the ...'s only as much as elements in $array. Even 'cloning' the array doing $arrclone = $array; foreach ($array as $n) { foreach ($arrclone as $n2) { ... } } the problem is the assignment of the array. Saying $arrclone = $array makes $arrclone adapt the same array-pointer, apparently. What does work is to include within the first foreach-loop: $arrclone[$n] = $array[$n]; It's a bit tricky, but it works :)

« previous php.notes (#50139) next »