Array Length in PHP
The length of an array is found using the
count
function:
<?php
$arr = [1, 2, 3];
echo count($arr); // will output 3
?>
Given the following array:
<?php
$arr = ['a', 'b', 'c', 'd', 'e'];
?>
Display the number of elements in this array.
Given the following array:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
?>
Display the number of elements in this array.