Home | About | Categories | All Tips & Tutorials

Count the number of elements in a PHP array using the count() function

ID: 45

Category: PHP7

Added: 15th of December 2015

Views: 2,892

To count the number of elements in a php array we use the php count function.
Copy and paste the code below in to your php file.

<?php
$colours=array("Blue","Red","Green","Orange");
echo "There are ". count($colours) ." elements in this array";
?>