我有这个饭_input_array
[Chicken Breast] => 11
[Marinated Dory] => 1
[Beef] => 3
foreach($meal_input_array as $meal_input_key => $meal_input_quantity)
{
$meal_data = $mean_input_key . "**" . $meal_input_quantity;
echo $meal_data;
}
当我回显结果时,我无法获得密钥,
**11**1**3**0
数组键名未分配给$ meal_data,我可以查看我的代码是否有错误。
谢谢!
答案 0 :(得分:1)
它有效
<?php
$meal_input_array=array('Chicken Breast' => 11, 'Marinated Dory' => 1,'Beef' => 3);
//print_r($meal_input_array);
foreach($meal_input_array as $meal_input_key => $meal_input_quantity)
{
//echo $meal_input_key;
$meal_data = $meal_input_key. " ** " .$meal_input_quantity;
echo $meal_data;
}