Counting the number of elements in an array uses a command called count.
First we will start with our original pantry array :
Now to count how many elements are in this array...
This will produce the result :
First we will start with our original pantry array :
<?php
$pantry = array(
1 => "apples",
2 => "oranges",
3 => "bananas"
);
?>
$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.";
?>
$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.

