我真的不知道如何解释我想做什么,所以这是一个例子。我有一个2D数组,就像这个:
Array
(
[0] => Array
(
[1] => value 1
[2] => value 2
)
[1] => Array
(
[1] => value 1
[2] => value 2
)
[2] => Array
(
[1] => value 1
[2] => value 2
)
)
我想有这个:
Array
(
[0] => Array
(
[1] => value 1
[2] => value 2
[3] => value 3
)
[1] => Array
(
[1] => value 1
[2] => value 2
[3] => value 3
)
[2] => Array
(
[1] => value 1
[2] => value 2
[3] => value 3
)
)
有人能帮助我吗?非常感谢。
答案 0 :(得分:1)
只需循环播放,并确保引用&
$val
来更新原始数组。然后只需附加新项目:
foreach($array as &$val) {
$val[] = 'value 3';
}
另一种方式:
foreach($array as $key => $val) {
$array[$key][] = 'value 3';
}