我在我的代码中遇到了这个问题,我想在 _cart-templet.php 文件中计算我的小计部分的价格,但它给了我错误,我在下面包含了这个错误的所有必要代码:
致命错误:未捕获错误:调用 C:\xampp\htdocs\MobileShopee\Mobile Shopee\Templet_cart-templet.php:78 中数组的成员函数 getSum() 堆栈跟踪:#0 C:\xampp\htdocs\MobileShopee\ Mobile Shopee\cart.php(10): include() #1 {main} throw in C:\xampp\htdocs\MobileShopee\Mobile Shopee\Templet_cart-templet.php on line 78"
主 cart.php 文件:
<?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');
?>
这是我的 Cart.php 文件:
public function getSum($arr){
if(isset($arr)){
$sum = 0;
foreach ($arr as $item){
$sum += floatval($item[0]);
}
return sprintf('%.2f' , $sum);
}
}
这是我的 functions.php 文件:
<?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);
MMTTMM
白猪掌柜的
眼眸繁星