Php operation array for ($ I = 1; $ I & lt; = 5; $ I ++) {array ($ I ));} the for loop contains a two-dimensional array. I want to merge the two-dimensional arrays in the for loop. The result is: array (& nbsp; [0] & nbsp; = & gt; & nbsp; Array php operation Array
for($i=1;$i<=5;$i++){
array(array($i));
}
The for loop contains a two-dimensional array. I want to merge the two-dimensional array in the for loop and print the result as follows:
array(
[0] => Array
(
[0] => 1
)
[1] => Array
(
[0] => 2
)
[2] => Array
(
[0] => 3
)
[3] => Array
(
[0] => 4
)
[4] => Array
(
[0] => 5
)
)
Share:
------ Solution --------------------
$rs = array();
for($i=0; $i<=5; $i++) {
$rs[] = array($i);
}
------ Solution --------------------
$res = array();
for($i=1;$i<=5;$i++){
$res = array_merge($res, array(array($i)));
}
print_r($res);
Array
(
[0] => Array
(
[0] => 1
)
[1] => Array
(
[0] => 2
)
[2] => Array
(
[0] => 3
)