Concept
How does PHP support and create multidimensional arrays?
ComputerScienceOne / Multidimensional Arrays
"PHP supports multidimensional arrays in the sense that elements in an array can be of any type, including other arrays. We can use the same syntax and operations for single dimensional arrays. For example, we can use the double arrow syntax and assign arrays as values to create a 2-dimensional array.\n\n$mat = array(\n\n0 => array(10, 20, 30),\n\n1 => array(40, 50, 60),\n\n2 => array(70, 80, 90)\n\n);\n\nprint_r($mat);\n\nWhich results in the following:\n\nArray (\n\n[0] => Array ( [0] => 10 [1] => 20 [2] => 30 )\n\n[1] => Array ( [0] => 40 [1] => 50 [2] => 60 )\n\n[2] => Array ( [0] => 70 [1] => 80 [2] => 90 )\n\n)"
Related Ideas
- How do you create and index arrays in PHP?ComputerScienceOne · Creating Arrays
- How can key-value pairs be initialized in a PHP array?ComputerScienceOne · Non-Contiguous Indices
- What types of elements can arrays contain?ComputerScienceOne · Arrays, Collections & Dynamic
- How can you print the contents of a PHP array in a readable format?ComputerScienceOne · Useful Functions
- How do you declare and allocate a two-dimensional array in Java?ComputerScienceOne · Multidimensional Arrays
- How do you create and populate a two-dimensional integer array?ComputerScienceOne · Dynamic Data Structures
- How can you iterate over indexed and associative arrays in PHP?ComputerScienceOne · Iteration
- How can you define arrays of strings in PHP?ComputerScienceOne · Arrays of Strings