note 20681 added to function.count

From: Date: Fri, 12 Apr 2002 09:25:02 +0000
Subject: note 20681 added to function.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-29148@lists.php.net to get a copy of this message
Someone said you couldn't use the for loop and count array command for processing arrays with missing entries. Well, heres my working idea: <? // Set up the array $holes = array ("first", 2 => "second", 5 => "fifth", "sixth"); // Note blank entries 3 and 4 //count number of entries, this time its 4 $array_count = count($holes); for($y=0; $y<$array_count; $y++) { if(isset($holes[$y])) { echo($holes[$y]); } else { $array_count++; } } // In the middle, check where array entry exists // If not, then increase the size of array_count // to reflect gaps in array. ?> -- http://www.php.net/manual/en/function.count.php http://master.php.net/manage/user-notes.php?action=edit+20681 http://master.php.net/manage/user-notes.php?action=delete+20681 http://master.php.net/manage/user-notes.php?action=reject+20681

« previous php.notes (#29148) next »