I have noticed several times, that everytime i try to execute a else if statement or just a else inside a for loop, most of the times it doesn't execute it properly or just completely ignores the else or the else if statement. I don't know if it is just some mistake from my part, but this happens to me quite often and i would like to know if anyone knows why this happens? I have an example below for those who are not catching what im trying to tell:
for($i = 1; $i<=12; $i++){
//$doughnutSelect = $_POST['doughnutSelect'];
${"doughnutSelect$i"} = $_POST["doughnutSelect{$i}"];
//echo ${"doughnutSelect$i"}.", ";
if(${"doughnutSelect$i"} == "Blueberry" || "Strawberry" || "Raspberry"){
$total = $total + 0.8;
}else if(${"doughnutSelect$i"} == "Caramel" || "Sprinkles"){
$total = $total + 1;
}else if(${"doughnutSelect$i"} == "Chocolate"){
$total = $total + 1.2;
}
}
So, right here i am getting 12 values from html selects and each select has only 6 options, "Blueberry", "Strawberry", "Raspberry", "Caramel", "Sprinkles" and "Chocolate" and i am using the for loop to save all of them in variables with the index $i but when i try to verify if my variable correspondes to any of them with else if's it just ignores the caramel, sprinkles and chocolate else if statements. That was a little confusing but i hope that all of you will be able to understand. Thank you.
Aucun commentaire:
Enregistrer un commentaire