jeudi 22 janvier 2015

What's wrong with my if statement in this code

the if condition of the method empty isn't echoing, I also tried to replace empty() by count($topping==0)... Any thoughts.



<?php
if ($_POST)
{
$topping = $_POST[topping];
if(empty($topping))
{
echo "You didn't select any Toppings. Booo!";
}
else
{

if(count($topping) == 1)
{
echo "Your order is a sandae with " . $topping[0];
}
elseif (count($topping) == 2) {

echo "Your order is a sandae with " . $topping[0] . " and ". $topping[1];
}
else {
$ch = "Your order is a sandae with " . $topping[0];
for ($i=1; $i < count($topping)-1 ; $i++) {
$ch = $ch . ", " . $topping[$i] ;
}
echo $ch . " and " . $topping[count($topping)-1];
}
}

Aucun commentaire:

Enregistrer un commentaire