-1
function countproduct(){
        $count = 0;
        $cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array();
        foreach($cart as $row):
            if($row['qty']!=0){
                $count = $count + 1;
            }
        endforeach;

        return $count;

i want to know whats the meaning of ? after the isset($_SESSION['cart'])

1 Answers1

1

It's a ternary operator, these line:

$cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array();

Can be transformed to:

if (isset($_SESSION['cart'])) {
    $cart = $_SESSION['cart'];
} else {
    $cart = array();
}

For more information you can check php operations documentation

T. AKROUT
  • 1,719
  • 8
  • 18