Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway to count how many keys an array has in Php?

Array
    (
        [0] => 'hello'
        [1] => 'there'
        [2] => 
        [3] => 
        [4] => 3
    )

// how to  get the number 5?
like image 273
Mohammad Avatar asked Nov 05 '10 13:11

Mohammad


1 Answers

count

$arr = Array
    (
        0 => 'hello',
        1 => 'there',
        2 => null,
        3 => null,
        4 => 3,
    );
var_dump(count($arr));

Output:

int(5)

like image 169
teemitzitrone Avatar answered Oct 11 '22 03:10

teemitzitrone