dt2002 2010-07-03 15:21
浏览 119
已采纳

在PHP中将一些新数据添加到数组中

I got an Array like this:

array('Testing'=>array(
'topic'=>$data['Testing']['topic'], 
'content'=>$data['Testing']'content'])
             ); 

Now I have got some new data to add into the Array shown aboved,
how can I do it so that the new Array will look like this:

array('Testing'=>array(
'topic'=>$data['Testing']['topic'], 
'content'=>$data['Testing']['content']),
'new'=>$data['Testing']['new'])
                 ); 

Could you help me please?

  • 写回答

2条回答 默认 最新

  • duancuan6466 2010-07-03 15:27
    关注

    In the same way that you can access arrays values by key, you can set by key, as well.

    <?php
    $array = array('foo' => array('bar' => 'baz'));
    $array['foo']['spam'] = 'eggs';
    var_export($array);
    

    Output:

    array (
      'foo' => 
      array (
        'bar' => 'baz',
        'spam' => 'eggs',
      ),
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?