To create a Three Dimensional Array in PHP, you can use nested arrays or array_fill() function.
In this example,
<?php
// Creating a 3D Array with Nested Arrays
$threeDArray = [[[0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0]]];
// Accessing and modifying elements
$threeDArray[1][0][2] = 5;
// Printing the array
print_r($threeDArray);
?>
Array ( [0] => Array ( [0] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) [1] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) ) [1] => Array ( [0] => Array ( [0] => 0 [1] => 0 [2] => 5 [3] => 0 ) [1] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) ) [2] => Array ( [0] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) [1] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 ) ) )
In this tutorial, we learned How to create a Three Dimensional Array in PHP language with well detailed examples.