3v4l.org

run code in 300+ PHP versions simultaneously
<?php class product { public function getData($key){ return ['total' => rand(1,999)]; } } class Mage { public static function getModel($name){ $class = __CLASS__; return new $class; } public function load($id){ return new product; } } class item { public function getProductId(){ return rand(1, 999); } } class order { public function getAllItems(){ return [new item, new item, new item]; } } $order = new order; $totalprofit = 0; foreach($order->getAllItems() as $item): $product = Mage::getModel('catalog/product')->load($item->getProductId()); $profit = $product->getData('profit'); $totalprofit += $profit['total']; echo $profit['total'], "\n"; endforeach; echo $totalprofit, "\n"; ?>

preferences:
35 ms | 402 KiB | 5 Q