Counting the number of elements in an array uses a command called count.
First we will start with our original pantry array :
<?php $pantry = array( 1 => "apples", 2 => "oranges", 3 => "bananas" ); ?>
Now to count how many elements are in this array...
<?php $total_elements = count($pantry); echo "There are $total_elements elements in the array."; ?> This will produce the result :
There are 3 elements in the array.
----------------- Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.
|