i'm having issues with the code i wrote up below. basically, when there are x items in the cart, it echoes the text "You have x item(s) in the cart". However, when there are no items, it should echo "You don't have any items in the cart" but instead echoes nothing. What am i doing wrong?
<?php
$array = unserialize($_SESSION['__vm']['vmcart']);
foreach($array->products as $product){
$amount = $product->amount;
if ($amount != 0){ echo "You have $amount item(s) in the cart."; }
else { echo "You don't have any items in the cart."; }
}
?>
Its because the code does not come in the for each loop.
<?php
$array = unserialize($_SESSION['__vm']['vmcart']);
if (count($array->products) > 0) {
foreach($array->products as $product){
$amount = $product->amount;
echo "You have $amount item(s) in the cart.";
/* Do other thinks here. */
}
} else {
echo "You don't have any items in the cart.";
}
?>
I'm not sure why you wanne use a loop btw.
Remove your foreach and use this
if($size=sizeof($array->products))
echo "You have ".$size." item(s) in the cart.";
else
echo "You don't have any items in the cart.";