Home > Article > Backend Development > Put values into two-dimensional array in PHP loop
The content of this article is to put values into a two-dimensional array in a PHP loop. It has a certain reference value. Now I share it with you. Friends in need can refer to it
$a = [];$b = ['a','b','c','d'];foreach($b as $v){ $a['a'][] = $v; }
$a
will get a two-dimensional array, but when using the following code, $a
will get It can only get one value, $a['a']
this array$b = ['a','b','c','d'];foreach($b as $v){ $a = []; $a['a'][] = $v; }
$a
is redefined once, so this phenomenon will occur. Related recommendations:
In-depth understanding of php loop statements
The above is the detailed content of Put values into two-dimensional array in PHP loop. For more information, please follow other related articles on the PHP Chinese website!