我有一个像这样的数组:
array('Testing'=>array(
'topic'=>$data['Testing']['topic'],
'content'=>$data['Testing']'content'])
);
现在我有一些新数据要添加到上面显示的数组中,
我该怎么做才能使新数组看起来像这样:
array('Testing'=>array(
'topic'=>$data['Testing']['topic'],
'content'=>$data['Testing']['content']),
'new'=>$data['Testing']['new'])
);
你能帮帮我吗?
最佳答案
与可以通过键访问数组值的方式相同,您也可以通过键进行设置。
<?php
$array = array('foo' => array('bar' => 'baz'));
$array['foo']['spam'] = 'eggs';
var_export($array);
输出:
array (
'foo' =>
array (
'bar' => 'baz',
'spam' => 'eggs',
),
)
关于php - 在 PHP 中将一些新数据添加到数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3171915/