Home Tutorial Php Examples PHP Get Array Length

 
 

PHP Get Array Length
Posted on: October 9, 2009 at 12:00 AM
PHP get array length tutorial show you how to count the elements of an array or no. of properties of an object

PHP Get Array Length

 To count the array length we use count method, it can be use to count the no. of properties of an object.

The structure of count is:

int count ($var [,int $mode=COUNT_NORMAL]);

Where 

$var is an array

mode is optional and we can set this parameter to COUNT_RECURSIVE (or 1), count() will recursively count the array. This option is beneficial for multidimensional array.Default value for this mode is 0.

 

Code:

<?php

$colorList = array("apple"=>"red",

"grass"=>"green",

"sky"=>"blue",

"night"=>"black",

"wall"=>"white");

echo "Array size with count: ".count($colorList);

?>

Output:

Array size with count: 5

Related Tags for PHP Get Array Length:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.