Logo

Programming-Idioms

History of Idiom 26 > diff from v26 to v27

Edit summary for version 27 by :
[PHP] specification of two dimension array of size m,n

Version 26

2016-02-19, 14:23:18

Version 27

2016-02-19, 14:56:31

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Code
$x = array(array(1,2), array(3,4));
Code
const M = 3;
const N = 5;
$x = array();
$x = array_pad($x, M, 1);
for($i = 0; $i < count($x); $i++){
  $x[$i] = array();
  $x[$i] = array_pad($x[$i],N,1);
}