Concept
How can two indices be used to set values in a two-dimensional PHP array?
ComputerScienceOne / Multidimensional Arrays
"Alternatively, you can use two indices to get and set values from a 2-dimensional array.\n\nfor($i=0; $i<3; $i++) {\n\nfor($j=0; $j<4; $j++) {\n\n$mat[$i][$j] = ($i+$j)*3;\n\n}\n\n}\n\nwhich results in:\n\nArray (\n\n[0] => Array ( [0] => 0 [1] => 3 [2] => 6 [3] => 9 )\n\n[1] => Array ( [0] => 3 [1] => 6 [2] => 9 [3] => 12 )\n\n[2] => Array ( [0] => 6 [1] => 9 [2] => 12 [3] => 15 )\n\n)"
Related Ideas
- How do you create and index arrays in PHP?ComputerScienceOne · Creating Arrays
- How do you declare and allocate a two-dimensional array in Java?ComputerScienceOne · Multidimensional Arrays
- How can you iterate over indexed and associative arrays in PHP?ComputerScienceOne · Iteration
- How are arrays passed to methods in Java?ComputerScienceOne · Multidimensional Arrays
- How do you create and populate a two-dimensional integer array?ComputerScienceOne · Dynamic Data Structures