I am facing this problem in my code where I want to calculate price to my subtotal section in \_cart-templet.php file but it give me error I included all the necessary code below for this error:

> 
> Fatal error: Uncaught Error: Call to a member function getSum() on array in C:\xampp\htdocs\MobileShopee\Mobile Shopee\Templet\_cart-templet.php:78 Stack trace: #0 C:\xampp\htdocs\MobileShopee\Mobile Shopee\cart.php(10): include() #1 {main} thrown in C:\xampp\htdocs\MobileShopee\Mobile Shopee\Templet\_cart-templet.php on line 78"
> 
> 
> 

main cart.php file:

```
<?php
ob_start();
//include header.php
include ('header.php');
?>
    <?php
    //include products.php
    include ('Templet/_cart-templet.php');

    //include top-sale.php
    include ('Templet/_new-phones.php');
    ?>

<?php
//include footer.php
include ('footer.php');
?>

```

This is my \_cart-templet.php file:

```
<!----Shopping section---->
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    if (isset($_POST['delete-cart-submit'])){
        $deletedRecord = $cart->deleteCart($_POST['item_id']);
    }

    // save for later
    if (isset($_POST['wishlist-submit'])){
        $cart->saveForLater($_POST['item_id']);
    }
}
?>
<section id="cart" class="py-3 mb-5">
    <div class="container-fluid w-75">
        <h5 class="font-baloo font-size-20">Shopping Cart</h5>
        <!--  shopping cart items   -->
        <div class="row">
            <div class="col-sm-9">
                <?php
                foreach ($product->getData('cart') as $item) :
                    $cart = $product->getProduct($item['item_id']);
                    $subTotal[] = array_map(function ($item){
                        ?>
                        <!-- cart item -->
                        <div class="row border-top py-3 mt-3">
                            <div class="col-sm-2">
                                <img src="<?php echo $item['item_image'] ?? "./assests/img/products/1.png" ;?>" style="height: 120px;" alt="cart1" class="img-fluid">
                            </div>
                            <div class="col-sm-8">
                                <h5 class="font-baloo font-size-20"><?php echo $item['item_name'] ?? "Unknown"; ?></h5>
                                <small>by <?php echo $item['item_brand'] ?? "Brand"; ?></small>
                                <!-- product rating -->
                                <div class="d-flex">
                                    <div class="rating text-warning font-size-12">
                                        <span><i class="fas fa-star"></i></span>
                                        <span><i class="fas fa-star"></i></span>
                                        <span><i class="fas fa-star"></i></span>
                                        <span><i class="fas fa-star"></i></span>
                                        <span><i class="far fa-star"></i></span>
                                    </div>
                                    <a href="#" class="px-2 font-rale font-size-14">20,534 ratings</a>
                                </div>
                                <!-- End product rating -->
                                <!-- product qty -->
                                <div class="qty d-flex pt-2">
                                    <div class="d-flex font-rale w-25">
                                        <button class="qty-up border bg-light" data-id="<?php echo $item['item_id'] ?? 0?>"><i class="fas fa-angle-up"></i></button>
                                        <input type="text" data-id="<?php echo $item['item_id'] ?? 0?>" class="qty_input border px-2 w-100 bg-light" disabled value="1" placeholder="1">
                                        <button data-id="<?php echo $item['item_id'] ?? 0?>" class="qty-down border bg-light"><i class="fas fa-angle-down"></i></button>
                                    </div>
                                    <form method="post">
                                        <input type="hidden" value="<?php echo $item['item_id'] ?? 0; ?>" name="item_id">
                                        <button type="submit" name="delete-cart-submit" class="btn font-baloo text-danger px-3 border-right">Delete</button>
                                    </form>
                                    <button type="submit" class="btn font-baloo text-danger">Save for Later</button>
                                </div>
                                <!-- End product qty -->
                            </div>
                            <div class="col-sm-2 text-right">
                                <div class="font-size-20 text-danger font-baloo">
                                    $<span class="product_price"><?php echo $item['item_price'] ?? 0; ?></span>
                                </div>
                            </div>
                        </div>
                        <!-- End cart item -->
                        <?php
                        return $item['item_price'];
                    }, $cart); // closing array_map function
                endforeach;
                ?>
            </div>
            <!-- subtotal section-->
            <div class="col-sm-3">
                <div class="sub-total border text-center mt-2">
                    <h6 class="font-size-12 font-rale text-success py-3"><i class="fas fa-check"></i> Your order is eligible for FREE Delivery.</h6>
                    <div class="border-top py-4">
                        <h5 class="font-baloo font-size-20">Subtotal (<?php echo isset($subTotal) ? count($subTotal) : 0; ?> items):&nbsp; <span class="text-danger">$<span class="text-danger" id="deal-price"><?php echo isset($subTotal) ? $cart->getSum($subTotal) : 0; ?></span> </span> </h5>
                        <button type="submit" class="btn btn-warning mt-3">Proceed to Buy</button>
                    </div>
                </div>
            </div>
            <!-- !subtotal section-->
        </div>
        <!-- End shopping cart items   -->
    </div>
</section>
<!----End Shopping section---->

```

This is my Cart.php file:

```
 public function getSum($arr){
        if(isset($arr)){
            $sum = 0;
            foreach ($arr as $item){
                $sum += floatval($item[0]);
            }
            return sprintf('%.2f' , $sum);
        }
    }

```

This my functions.php file:

```
<?php
//require MYSQL Connection
require ("database/DBController.php");
//require product class
require ("database/Product.php");
//require product class
require ("database/Blog.php");
//require cart class
require ("database/Cart.php");
//DB Controller
$db = new DBController();
//product object
$product = new Product($db);
$product_shuffle = $product->getData();
//blog object
$blog = new Blog($db);
//cart object
$cart = new Cart($db);

```