我有一个多维数组$md_array,我想从一个循环中读取数据并向子数组recipe_type和cuisine添加更多元素。
在循环中,我为每一行创建一个新的表$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数组的语法是什么?我从来没有理解过多维数组,有点困惑。
$id = mysql_insert_id()
,那么我就可以执行$md_array["recipe_type"][$id] = $newdata
,是吗? - bikey77