我有一个如下所示的数组:
Array(
[0] => Array
(
[id] => 39
[countNew] => 0
[nume] => Ardeleanu
) )
如何在现有数组中添加新字段,使其如下所示:
Array(
[0] => Array
(
[id] => 39
[countNew] => 0
[nume] => Ardeleanu
[migr] => 0
) )
我尝试了阵列推送,但我得到了类似的东西:
Array(
[0] => Array
(
[id] => 39
[countNew] => 0
[nume] => Ardeleanu
[0] => Array
(
[migr] => 0
)
) )
答案 0 :(得分:4)
Justr尝试:
$input = array(/* your data */);
$input[0]['migr'] = 0;
或者:
$input = array(/* your data */);
$additional = array('migr' => 0);
$input[0] = array_merge($input[0], $additional);