3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Un panier d'achat simple, qui contient une liste de produits // choisis et la quantité désirée de chaque produit. Il inclut // une méthode qui calcule le prix total des éléments dans le panier // en utilisant une fonction de rappel anonyme. class Panier { const PRICE_BEURRE = 1.00; const PRICE_LAIT = 3.00; const PRICE_OEUF = 6.95; protected $products = array(); public function add($product, $quantity) { $this->products[$product] = $quantity; } public function getQuantity($product) { return isset($this->products[$product]) ? $this->products[$product] : FALSE; } public function getTotal($tax) { $total = 0.00; $callback = function ($quantity, $product) use ($tax, &$total, $this) { $test = $this->products; $pricePerItem = constant(__CLASS__ . "::PRICE_" . strtoupper($product)); $total += ($pricePerItem * $quantity) * ($tax + 1.0); }; array_walk($this->products, $callback); return round($total, 2); } } $mon_panier = new Panier; // Ajout d'élément au panier $mon_panier->add('beurre', 1); $mon_panier->add('lait', 3); $mon_panier->add('oeuf', 6); // Affichage du prix avec 5.5% de TVA print $mon_panier->getTotal(0.055) . "\n";

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.5.30.0070.07320.11
5.5.20.0030.08020.01
5.5.10.0000.05320.03
5.5.00.0070.07320.18
5.4.190.0070.07319.02
5.4.180.0070.06719.16
5.4.170.0000.07318.90
5.4.160.0000.07719.04
5.4.150.0030.07719.14
5.4.140.0070.07016.50
5.4.130.0030.07016.37
5.4.120.0030.05316.39
5.4.110.0030.05316.47
5.4.100.0130.06316.58
5.4.90.0000.07016.40
5.4.80.0070.04316.47
5.4.70.0000.07316.46
5.4.60.0070.06716.34
5.4.50.0030.07016.34
5.4.40.0030.06716.51
5.4.30.0000.06716.36
5.4.20.0000.03716.48
5.4.10.0030.07316.32
5.4.00.0070.05715.89
5.3.270.0030.08314.64
5.3.260.0100.07014.58
5.3.250.0000.07714.50
5.3.240.0070.07014.59
5.3.230.0030.07314.64
5.3.220.0030.07314.64
5.3.210.0000.06714.63
5.3.200.0030.07014.59
5.3.190.0000.07714.68
5.3.180.0030.05714.59
5.3.170.0030.06014.64
5.3.160.0000.07314.64
5.3.150.0030.07014.69
5.3.140.0000.07314.67
5.3.130.0030.07014.62
5.3.120.0030.06714.55
5.3.110.0030.07714.64
5.3.100.0130.06014.07
5.3.90.0070.07314.00
5.3.80.0030.07314.13
5.3.70.0030.07014.13
5.3.60.0030.05314.00
5.3.50.0030.07014.03
5.3.40.0100.07014.04
5.3.30.0000.07314.00
5.3.20.0030.07013.61
5.3.10.0070.06013.71
5.3.00.0000.07313.66

preferences:
142.33 ms | 1394 KiB | 7 Q