PHP Array Counting

0
309
PHP Array count

Think you know PHP array counting?

Test yourself in this quiz of your knowledge of counting PHP array elements.

$aWords = array();
echo count($aWords);

Result:
0

$aWords["one"] = array();
echo count($aWords["one"]);

Result:
0

$aWords["one"] = array();
echo count($aWords);

Result:
1

$aWords["one"] = array();
$aWords["two"] = array();
echo count($aWords);

Result:
2

$aWords[] = array();
var_dump($aWords);
echo count($aWords);

Result:

array
  0 => 
    array
      empty
1
$aWords[0] = array();
$aWords[1] = array();
$aWords[1][0] = "hello";
var_dump($aWords);
echo $aWords[0] . "<br>";
echo $aWords[1] . "<br>";
echo $aWords[1][0] . "<br>";
echo count($aWords);

Result:

array
  0 => 
    array
      empty
  1 => 
    array
      0 => string 'hello' (length=5)
Array
Array
hello
2

Of Interest