By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

PHP Count Function

This function can be used to count the elements inside an array.

Edited: 2012-12-27 21:15

The PHP Count function can be used to count the elements in an array.

Tutorial: Determine PHP Array Length

Parameters

VarThe array or object you want to count.
ModeIf this is set to either COUNT_RECURSIVE or 1, count will recursively count the array, useful when working with multidimensional arrays.

PHP Count Example

<?php
  $a[0] = "First array element";
  $a[1] = "Second array element";
  $a[2] = "Third array element";
  $result = count($a); // The result is 3
?>