note 34550 deleted from control-structures.foreach by didou

From: Date: Wed, 30 Jul 2003 15:53:07 +0000
Subject: note 34550 deleted from control-structures.foreach by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-53017@lists.php.net to get a copy of this message
Note Submitter: raevanmorlock@hotmail.com ---- If you need to retain any modifications to the values of the array while looping through it, I've found this to be a good method: Instead of this: foreach ($arr as $a) { $a['name'] = "Bob"; } Use this: for ($i=0; $i < count($arr); $i++) { $a = &$arr[$i]; $a['name'] = "Bob"; }

« previous php.notes (#53017) next »