13

As each() loop is deprecated since PHP 7.2, how to update the below while(() = each()) loop without $value?

Without the $value I can't get foreach loop to work. In addition while($products_id = $this->contents) results in infinite loop.

Thank you!

$total_items = 0;

reset($this->contents);
while (list($products_id, ) = each($this->contents)) {
    $total_items += $this->get_quantity($products_id);
}
Petro Mäntylä
  • 711
  • 1
  • 7
  • 9

0 Answers0