由于每个()循环从PHP 7.2开始不推荐使用,如何在没有$ value的情况下更新下面的while((= = each())循环?
如果没有$ value,我就无法使foreach循环工作。另外,while($ products_id = $ this-> contents)导致无限循环。
谢谢!
function count_contents() { // get total number of items in cart
$total_items = 0;
if (is_array($this->contents)) {
reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
$total_items += $this->get_quantity($products_id);
}
}
return $total_items;
}
function get_quantity($products_id) {
if (isset($this->contents[$products_id])) {
return $this->contents[$products_id]['qty'];
} else {
return 0;
}
}