pTutorial

New way to learn PHP function

PHP count() function

Syntax

  count($array [, mode])
  
Parameter Description
Array array to count (Required)
Mode 0 for one dimensional array (optional)

Note: If you want to count one dimensional array then option set 0 but default its zero so there is no requirement to set zero.

.

In case of multidimensional array mode will set 1, it's compulsory.

Definition

It returns number of element in an array.

Usage

Count function is used to find the number of element in an array.

Example of array count function

<?php

$name = array ("php","java","html");

$a=count($name);

echo "Number of element in an array: ";

echo $a;
 
?>

In above example $name is an array variable that hold the three element. You can use count() function to find the number of element in an array.

Count function is very useful at the time of huge amount of data.

More example of array count function

<?php

$name = array ("php","java","html");

print_r($name);

$a=count($name);

echo "
Number of element in an array: "; echo $a; ?>

In above example you can check number of element by using print_r() function, With the help of print_r() function yop can print the key and value of the array.

QUOTES OF THE DAY

To make your children capable of honesty is beginning of education.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER