• Post category:PHP

How to Count Array Values in PHP

Count Array Values in PHP

Learn how to count array values in php with example codes. To count array values, we need to use the count() function. An important task when using arrays, especially in combination with loops, is finding out how many values the array contains. This is easily accomplished with PHP’s count() function, which accepts the array variable as a parameter and returns an integer value indicating how many elements it contains. Instead of the count() function, we can also use the size of the () function, which does the same thing.


//define array
$data = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
//get array size
echo 'The array has ' . count($data) . ' elements';


count array values in php

Leave a Reply