Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将新数据放入PHP数组中的特定键_Php_Arrays - Fatal编程技术网

将新数据放入PHP数组中的特定键

将新数据放入PHP数组中的特定键,php,arrays,Php,Arrays,我想在不修改任何现有键或值的情况下向现有数组添加一些数据 原始数组如下所示: array( 'sections' => array( array( 'id' => 'sections_id', 'title' => 'sections_title' ) ), 'settings' => array( array( 'id' =&

我想在不修改任何现有键或值的情况下向现有数组添加一些数据

原始数组如下所示:

array(
    'sections' => array(
        array(
            'id' => 'sections_id',
            'title' => 'sections_title'
        )

    ),
    'settings' => array(
        array(
            'id' => 'settings_id',
            'title' => 'settings_title'
        )
    )
);
现在,我希望能够将新数组添加到sections键和settings键,从而将以下内容转换为:

array(
    'sections' => array(
        array(
            'id' => 'sections_id',
            'title' => 'sections_title'
        ),
        array(
            'id' => 'NEW_sections_id',
            'title' => 'NEW_sections_title'
        )           
    ),
    'settings' => array(
        array(
            'id' => 'settings_id',
            'title' => 'settings_title'
        ),
        array(
            'id' => 'NEW_settings_id',
            'title' => 'NEW_settings_title'
        )
    )
);
我尝试过使用array\u push和array\u merge,但没有成功,希望有人能帮助我


谢谢大家!

您可以像处理任何其他数组一样执行此操作

$array['sections'][] = array('id' => 'sec_id', 'title' => 'sec_title');

您可以像处理任何其他阵列一样执行此操作

$array['sections'][] = array('id' => 'sec_id', 'title' => 'sec_title');

thnx@Martin很快:thnx@Martin很快: