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 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 do nested for loops execute in PHP?ComputerScienceOne · Nested Loops
- How can pointer manipulation create a contiguous two-dimensional array?ComputerScienceOne · Contiguous 2-D Arrays
- Can PHP array indices be non-contiguous?ComputerScienceOne · Strings as Indices
- How can strings be used as indices in PHP arrays?ComputerScienceOne · Non-Contiguous Indices
- How can key-value pairs be initialized in a PHP array?ComputerScienceOne · Non-Contiguous Indices