Bifalgorithm post · Computer science one · Multidimensional Arrays

How does PHP support and create multidimensional arrays?

How does PHP support and create multidimensional arrays? (Computer science one · Multidimensional Arrays) — "PHP supports multidimensional arrays in the sense…

Ideas in this flowchart

  • PHP supports multidimensional arrays.
  • An array element can have any type, including another array.
  • The same syntax and operations used for single-dimensional arrays also apply.
  • A two-dimensional array can be created by assigning arrays as values with double-arrow syntax.
  • $mat = array(0 => array(10, 20, 30), 1 => array(40, 50, 60), 2 => array(70, 80, 90));
  • The array can be displayed with print_r($mat).
  • The result contains three indexed inner arrays, each holding three values.
Feed/

How does PHP support and create multidimensional arrays?

No cover

Channel

Computer science one

1 page

"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)"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.