Counting Array Elements
<?php
$dogs = array('A' => 'AA', 'Bud' => 'BB', 'C' => 'D');
$birds = array('parrot', 'magpie', 'lorakeet', 'cuckoo');
printf("<p>There are %d dogs and %d birds.</p>", count($dogs), count($birds));
$birds[] = 'ibis';
printf("<p>There are %d birds:</p>", count($birds));
printf("<pre>%s</pre>\n", var_export($birds, TRUE));
$birds[10] = 'heron';
unset($birds[3]);
printf("<p>There are %d birds:</p>", count($birds));
printf("<pre>%s</pre>\n", var_export($birds, TRUE));
?>
Related examples in the same category