我想在不修改任何现有键或值的情况下向现有数组添加一些数据.
原始数组是这样的:
array(
'sections' => array(
array(
'id' => 'sections_id',
'title' => 'sections_title'
)
),
'settings' => array(
array(
'id' => 'settings_id',
'title' => 'settings_title'
)
)
);
Run Code Online (Sandbox Code Playgroud)
现在我希望能够将新数组添加到sections键和设置键,以便将以下内容转换为:
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'
)
)
);
Run Code Online (Sandbox Code Playgroud)
我尝试使用array_push和array_merge没有成功,我希望有人可以提供帮助.
谢谢!
你会像任何其他阵列一样做.
$array['sections'][] = array('id' => 'sec_id', 'title' => 'sec_title');
Run Code Online (Sandbox Code Playgroud)