Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
function getCartQty()
    {
        if(empty($_SESSION['cart']))
            return 0;
        $qty = array();
        foreach($_SESSION["cart"] as $item){
            $qty[] =  $item['quantity'];
        }
        return array_sum($quantity);
    }


What I have tried:

PHP
function getCartQty()
    {
        if(empty($_SESSION['cart']))
            return 0;
        $qty = array();
        foreach($_SESSION["cart"] as $item){
            $qty[] =  $item['quantity'];
        }
        return array_sum($quantity);
    }
Posted
Updated 28-Apr-22 21:40pm
v3

Probably not.
Since $qty is the array you fill from the cart and $quantity is a different variable altogether, it's unlikely that summing it's values will give you the right total ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900