Do I need to calculate how many keys an array has in php?

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

// how to  get the number 5?
+5
source share
5 answers

count

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

Conclusion:

INT (5)

+20
source
+3
source

w/NULL

$array = array('hello', 'there', NULL, NULL, 3);

echo "<pre>".print_r($array, true)."</pre><br />";
echo "Count: ".count($array)."<br />";

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

Count: 5

Google PHP-

+2

PHP 5.3.2. int 5.

$a = array(
    0 => 'hello',
    1 => 'there',
    2 => null,
    3 => null,
    4 => 3,
);

var_dump(count($a));

null, ? , ? ?:)

: , :)

0
echo count($array);
0

All Articles