How to get length of an array in PHP ?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Dec 07, 2018

 

    2 Answers Written

  •  Sharad Jaiswal
    Answered by poorna

    PHP array count

    In PHP Programming Language we can get count or the total number of elements of an array using count() function.

    count() function in PHP is used to get the length of an array.

    Syntax:

    count(var array_variable, mode)

    Where array_variable is variable whose elements to be counted and the mode is an optional argument to specify the mode to be the use of counting recursive or normal

    Usage:

    $php_array= [1,10,5,38];
    echo count($php_array); // prints 4 as output.
    
  •  Sharad Jaiswal
    Answered by Sharad Jaiswal

    You can get the length of an array in PHP by using

    • count — Count all elements in an array, or in an object
    • sizeof — Alias of count()

Please Login or Register to leave a response.

Related Questions

PHP Interview Questions

What is T_PAAMAYIM_NEKUDOTAYIM ?

T_PAAMAYIM_NEKUDOTAYIM is scope resolution operator used as :: (double colon) .Basically, it used to call static methods/variables of a Class...

PHP Interview Questions

What is the difference between == and === operator in PHP ?

In PHP == is equal operator and returns TRUE if $a is equal to $b after type juggling and === is Identical operator and return TRUE if $a is equal to $b, and they are of the same data type...

Ask a Question