PHP 将元素添加到具有array_push的多维数组
2022-08-30 08:51:53
我有一个多维数组$md_array,我想向子数组添加更多元素,recipe_type和来自从表中读取数据的循环的美食。
在循环中,我为每行创建一个新的表$newdata:
$newdata = array (
'wpseo_title' => 'test',
'wpseo_desc' => 'test',
'wpseo_metakey' => 'test'
);
然后,使用我需要将$newdata数组附加到以下多维数组:array_push()
$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数组的语法是什么?我永远无法理解多维数组,我有点困惑。