Three-Dimensional Array in PHP
Here is an example of a three-dimensional array:
<?php
$arr = [
[
['a', 'b'],
['c', 'd'],
],
[
['e', 'f'],
['g', 'h'],
],
[
['i', 'j'],
['k', 'l'],
],
];
?>
To output elements from such an array, it is already necessary to write three square brackets:
<?php
echo $arr[0][0][0]; // outputs 'a'
echo $arr[2][1][0]; // outputs 'k'
?>
Given the following array:
<?php
$arr = [
[
[1, 2],
[3, 4],
],
[
[5, 6],
[7, 8],
],
];
?>
Find the sum of all elements of the given array.