你能解释为什么这总是通过第一个if语句条件,显然不对吗?!
非常感谢你的帮助!
$meal_plan = array();
// meal macros
$meal_macros = array['meals_per_day' => 6];
$test = $meal_macros['meals_per_day'];
if( $test == 4 ) {
$meal_plan = array(
'breakfast' => [],
'lunch' => [],
'snack' => [],
'dinner' => []
);
} elseif( $test == 5 ) {
$meal_plan = array(
'breakfast' => [],
'snack' => [],
'lunch' => [],
'snack' => [],
'dinner' => []
);
} elseif( $test == 6 ) {
$meal_plan = array(
'breakfast' => [],
'snack' => [],
'lunch' => [],
'snack' => [],
'dinner' => [],
'snack' => []
);
} else {
$meal_plan = array(
'breakfast' => [],
'snack' => [],
'lunch' => [],
'snack' => [],
'dinner' => [],
'snack' => []
);
}
P> S> 请忽略此文,我写这个,所以我可以发布这个问题。后置过滤器告诉我在问题代码中没有足够的文本,所以我添加了一些。 LOL
答案 0 :(得分:0)
我发现问题是什么,你不能在数组中使用相同的键!我在同一个阵列中多次使用'零食'作为关键。感谢大家的投入!