Tuesday, 11 June 2013

How to get the size of array in php?

We can find out the size of array in 2 ways in php.

  1. Sizeof function
  2. Count function

Example with code and syntax - 


So if you have an array say 

$myarr = array('sd','fgf')

echo count($myarr) ;

//This will print 2 .

Both functions take second argument as 0 or 1.

If you pass 0, then it will not count all elements of multi dimensional array
If you pass 1, then it will count all elements of multi dimensional array

This is how you can get the size of array. Or total number of elements in array in php.

No comments:

Post a Comment