我有一个多维数组 $md_array,我想将更多元素添加到子数组 recipe_type 和来自从表中读取数据的循环中的美食。
在循环中,我为每一行创建一个新表 $newdata:
$newdata = array (
'wpseo_title' => 'test',
'wpseo_desc' => 'test',
'wpseo_metakey' => 'test'
);
然后,使用array_push()
我需要将 $newdata 数组附加到以下多维数组:
$md_array= array (
'recipe_type' =>
array (
18 =>
array (
'wpseo_title' => 'Salads',
'wpseo_desc' => 'Hundreads of recipes for Salads',
'wpseo_metakey' => ''
),
19 =>
array (
'wpseo_title' => 'Main dishes',
'wpseo_desc' => 'Hundreads of recipes for Main dishes',
'wpseo_metakey' => ''
)
),
'cuisine' =>
array (
22 =>
array (
'wpseo_title' => 'Italian',
'wpseo_desc' => 'Secrets from Sicily in a click',
'wpseo_metakey' => ''
),
23 =>
array (
'wpseo_title' => 'Chinese',
'wpseo_desc' => 'Oriental dishes were never this easy to make',
'wpseo_metakey' => ''
),
24 =>
array (
'wpseo_title' => 'Greek',
'wpseo_desc' => 'Traditional Greek flavors in easy to make recipies',
'wpseo_metakey' => ''
)
)
);
使用 array_push 向 recipe_type 数组添加新元素(数组)的语法是什么?我永远无法理解多维数组,我有点困惑。