How can you count the content of a multidimensional array in PHP?
To count the content of a multidimensional array in PHP, you can use the `count()` function along with a loop to iterate through the array and count each element. You can recursively loop through each dimension of the array to count all elements, including nested arrays.
function countMultiArray($array) {
$count = 0;
foreach ($array as $element) {
if (is_array($element)) {
$count += countMultiArray($element);
} else {
$count++;
}
}
return $count;
}
$multiArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
$totalCount = countMultiArray($multiArray);
echo "Total count of elements in the multidimensional array: " . $totalCount;