How to create a multidimensional array in PHP?

To create a multidimensional array in PHP, you can use the array() function or the [] syntax. Here's an example:

// Using the array() function $multiArray = array( array(1, 2, 3), array('a', 'b', 'c'), array(true, false, true) ); // Using the [] syntax (available in PHP 5.4+) $multiArray = [ [1, 2, 3], ['a', 'b', 'c'], [true, false, true] ];

In both cases, we have created a 2-dimensional array with 3 rows and 3 columns. Each element within the outer array is an inner array, forming the rows and columns.

To access specific elements within the multidimensional array, you can use the index of each dimension. For example:

echo $multiArray[0][1]; // Output: 2 echo $multiArray[1][2]; // Output: c echo $multiArray[2][0]; // Output: 1

You can also use loops to iterate over the multidimensional array and perform operations on each element.