note 32713 added to function.count

From: Date: Thu, 05 Jun 2003 01:42:05 +0000
Subject: note 32713 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-49754@lists.php.net to get a copy of this message
in response to joshua dot patterson a+ plexus dot com above this, instead of using: ////////////////////////////// $tCount = count($array); for ($i=0;$i<$tCount;$i++) { Some Code if ($someVar==4) { array_splice($array,$i,1); $tCount--; } } ///////////////////////////////// try using foreach as follows: foreach($Array) //this steps through each value that an array has in it. { Some Code } or even: foreach($Array as $Key => $Value) //$Key is equal to the array key number and $Value is //equal to the value at $Key. { Some Code } im unsure of how it works with multi dimensional arrays or if it is faster but i would think it is. ---- Manual Page -- http://www.php.net/manual/en/function.count.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32713 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32713&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32713&report=yes

« previous php.notes (#49754) next »