note 20681 deleted from function.count by bjori
| From: | bjori@php.net | Date: | Tue, 03 Apr 2007 12:03:19 +0000 |
| Subject: | note 20681 deleted from function.count by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125039@lists.php.net to get a copy of this message | ||
Note Submitter: markis dot brachel at ntlworld dot com
----
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.
?>