j'ai une chaine variable, que je passe en tableau avec explode, ensuite je compare chaque valeur.
$diet=explode(',', $dietaryOptions);
foreach ($diet as $d) {
//echo $d.', ';
if (($d=='Diabetique')) {
echo '1 :: ';
}else if($d=='Vegetarian'){
echo '2 :: ';
}else if($d=='Vegan'){
echo '3';
}else if($d=='No sugar'){
echo '4 :: ';
}else if($d=='100% organic'){
echo '5 :: ';
}else if($d=='No nuts'){
echo '6 :: ';
}else if($d=='Low fat'){
echo '7 :: ';
}else if($d=='Gluten free'){
echo '8 :: ';
}else if($d=='No milk'){
echo '9 :: ';
}else{
echo 'aucun';
}
/*
$Diabetique=($d=='Diabetique')?'coche':'interdit';
$Vegetarian=($d=='Vegetarian')?'coche':'interdit';
$Vegan=($d=='Vegan')?'coche':'interdit';
$noSugar=($d=='No sugar')?'coche':'interdit';
$organic=($d=='100% organic')?'coche':'interdit';
$noNuts=($d=='No nuts')?'coche':'interdit';
$lowFat=($d=='Low fat')?'coche':'interdit';
$glutenFree=($d=='Gluten free')?'coche':'interdit';
$noMilk=($d=='No milk')?'coche':'interdit';
*/
}
Le problème c'est que ça imprime :1 :: aucunaucunaucunaucunaucunaucun
alors que ça doit imprimer le résultat en fonction du tableau $diet qui contient ces valeurs :
Diabetique, Vegetarian, Vegan, No sugar, No nuts, Low fat, No milk,
Merci