3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Card { private $suit; private $val; public function __construct($val, $suit) { $values = array( '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, '10' => 10, 'J' => 11, 'Q' => 12, 'K' => 13, 'A' => 14, ); $suits = array( 'H' => 'Hearts', 'C' => 'Clubs', 'D' => 'Diamonds', 'S' => 'Spades' ); $this->suit = $suits[$suit]; $this->val = $values[$val]; } public function getSuit() { return $this->suit; } public function getVal() { return $this->val; } } class Hand { private $cards; private $matches = array(); public function __construct($hand) { $cards = explode(' ', $hand); foreach ($cards as $card) { $val = substr($card, 0, -1); $suit = strtoupper(substr($card, -1)); $this->cards[] = new Card($val, $suit); } $this->isPair(); $this->isHighCard(); $this->isKind(); $this->isStraight(); } public function getCards(){ return $this->cards; } public function getValues(){ foreach($this->cards as $card){ $output[] = $card->getVal(); } return $output; } public function isHighCard(){ $output = max($this->getValues()); return $output; } public function isPair(){ foreach(array_count_values($this->getValues()) as $value => $count){ if ($count == 2 && count($this->matches) < 2) { $this->matches[] = $value; } } if (count($this->matches) == 1) { echo "One pair"; } if (count($this->matches) == 2) { echo "Two pair"; } } public function isKind(){ $count = max(array_count_values($this->getValues())); if($count == 3){ echo "Three of a kind"; } if($count == 4){ echo "Four of a kind"; } } public function isStraight(){ $cards = $this->getValues(); $previous = null; foreach($cards as $card){ if ($previous !== null && $card == $previous + 1){ echo "Straight"; } $previous = $card; } } } $h = new Hand('6h 7d 8s 9c 10h'); // var_dump($x);
based on T5kHX

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)
8.0.30.0130.01517.35
8.0.20.0060.01517.01
8.0.00.0110.00916.82
7.4.160.0080.01016.62
7.4.140.0100.01417.86
7.4.130.0140.00716.50
7.4.120.0060.01616.49
7.4.110.0150.00316.57
7.4.100.0080.01116.71
7.4.90.0120.00916.57
7.4.80.0110.00819.39
7.4.70.0110.00816.56
7.4.60.0150.00316.60
7.4.50.0060.01216.44
7.4.40.0120.00516.35
7.4.00.0060.00915.11
7.3.280.0050.01116.37
7.3.260.0070.01116.61
7.3.240.0120.00716.49
7.3.230.0170.00416.43
7.3.210.0030.01416.68
7.3.200.0140.00316.68
7.3.190.0120.00916.72
7.3.180.0090.00916.40
7.3.170.0100.00616.55
7.3.160.0130.00316.53
7.3.40.0210.00314.95
7.3.30.0080.00314.64
7.3.20.0140.00716.64
7.3.10.0100.01216.57
7.3.00.0130.01016.52
7.2.330.0150.00316.47
7.2.320.0060.01316.78
7.2.310.0110.00616.87
7.2.300.0100.00716.81
7.2.290.0040.01216.75
7.2.170.0070.01015.07
7.2.160.0070.00415.08
7.2.150.0130.00916.83
7.2.140.0060.00616.77
7.2.130.0090.00616.81
7.2.120.0100.00316.68
7.2.110.0120.00916.95
7.2.100.0170.00316.98
7.2.90.0090.00317.04
7.2.80.0120.00017.09
7.2.70.0030.00717.03
7.2.60.0050.00516.98
7.2.50.0030.00917.00
7.2.40.0040.00816.90
7.2.30.0070.01416.96
7.2.20.0090.01616.96
7.2.10.0030.01016.84
7.2.00.0000.01116.91
7.1.280.0100.00015.41
7.1.270.0030.01715.68
7.1.260.0150.00615.67
7.1.250.0030.01715.67