3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Card { private $suit; private $val; public function __construct($val, $suit) { $values = array( '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] ?? $val; } public function getSuit() { return $this->suit; } public function getVal() { return $this->val; } public function setVal($val) { $this->val = $val; } } class Hand { private $cards; private $matches = array(); private $values = array(); private $flush; 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); } // get values of cards in hand $this->values = array_map(function ($card) { return $card->getVal(); }, $this->cards); // get suits of cards in hand $this->suits = array_map(function ($card) { return $card->getSuit(); }, $this->cards); // get pairs of threes and fours $this->pairs = $this->threes = $this->fours = []; // might be a straight $this->possibleStraight = true; $this->hands = array_count_values($this->values); // if there are more than 2 same card values, it can't be a straight if (max($this->hands) > 1) { $this->possibleStraight = false; } // match for pairs foreach ($this->hands as $face => $count) { // one or two pairs if ($count === 2) { $this->pairs[] = $face; } // three of a kind if ($count === 3) { $this->threes[] = $face; } // four of a kind if ($count === 4) { $this->fours[] = $face; } } } public function getCards() { return $this->cards; } public function getValues() { return $this->values; } public function getSuits() { return $this->suits; } public function getHighCard() { return max($this->getValues()); } public function getPairs() { return $this->pairs; } public function isOnePair(){ return (count($this->pairs) == 1 ? true : false); } public function isTwoPair(){ return (count($this->pairs) == 2 ? true : false); } public function getThrees() { return $this->threes; } public function getFours() { return $this->fours; } public function hasAce() { return isset($this->hands['14']); } public function isFullHouse() { return count($this->pairs) == 1 && count($this->threes) == 1; } public function isStraight() { if (!$this->possibleStraight) { return false; } // if ($this->hasAce()) { } } public function isFlush() { $this->suits = array_count_values($this->getSuits()); // match flush foreach ($this->suits as $face => $count) { if ($count == 5) { $this->flush = true; } } return $this->flush; } } $h = new Hand('Ah As 10c 7d 7s'); var_dump($h->getHighCard()); var_dump($h->isOnePair()); var_dump($h->isTwoPair()); var_dump($h->getThrees()); var_dump($h->getFours()); var_dump($h->isFullHouse()); var_dump($h->isFlush());

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.3.60.0130.00718.68
8.3.50.0060.01017.42
8.3.40.0040.01119.03
8.3.30.0000.01518.88
8.3.20.0050.00221.73
8.3.10.0030.00522.00
8.3.00.0080.00021.89
8.2.180.0090.00616.63
8.2.170.0160.00322.96
8.2.160.0090.00620.41
8.2.150.0000.00724.18
8.2.140.0060.00324.66
8.2.130.0030.00719.66
8.2.120.0000.00826.35
8.2.110.0040.00722.03
8.2.100.0090.00318.03
8.2.90.0060.00318.00
8.2.80.0080.00018.18
8.2.70.0040.00418.05
8.2.60.0000.00818.30
8.2.50.0040.00418.10
8.2.40.0040.00419.59
8.2.30.0040.00420.48
8.2.20.0000.01018.11
8.2.10.0070.00019.49
8.2.00.0050.00218.11
8.1.280.0110.00725.92
8.1.270.0040.00423.96
8.1.260.0050.00226.35
8.1.250.0060.00328.09
8.1.240.0100.00022.46
8.1.230.0090.00321.09
8.1.220.0030.00517.77
8.1.210.0000.01018.82
8.1.200.0040.00417.48
8.1.190.0030.00617.23
8.1.180.0040.00418.10
8.1.170.0000.00818.57
8.1.160.0030.00518.91
8.1.150.0040.00418.98
8.1.140.0050.00319.01
8.1.130.0100.00017.57
8.1.120.0110.00017.52
8.1.110.0030.00617.44
8.1.100.0040.00417.60
8.1.90.0030.00517.55
8.1.80.0000.00817.45
8.1.70.0000.00717.53
8.1.60.0030.00517.58
8.1.50.0000.00917.65
8.1.40.0000.00817.59
8.1.30.0070.00317.75
8.1.20.0030.00617.70
8.1.10.0030.00617.68
8.1.00.0000.00817.49
8.0.300.0030.00519.98
8.0.290.0000.00716.88
8.0.280.0000.00718.53
8.0.270.0070.00217.28
8.0.260.0050.00516.82
8.0.250.0030.00316.94
8.0.240.0030.00617.04
8.0.230.0000.00717.05
8.0.220.0040.00416.88
8.0.210.0040.00416.96
8.0.200.0040.00417.05
8.0.190.0050.00316.97
8.0.180.0040.00417.02
8.0.170.0060.00317.05
8.0.160.0040.00716.91
8.0.150.0000.00716.96
8.0.140.0030.00616.93
8.0.130.0030.00313.49
8.0.120.0030.00516.94
8.0.110.0080.00016.82
8.0.100.0040.00416.87
8.0.90.0050.00216.94
8.0.80.0080.00816.96
8.0.70.0050.00316.83
8.0.60.0040.00416.94
8.0.50.0040.00416.97
8.0.30.0100.00817.06
8.0.20.0110.00917.28
8.0.10.0030.00616.93
8.0.00.0120.00916.82
7.4.330.0050.00015.55
7.4.320.0000.00616.61
7.4.300.0060.00316.67
7.4.290.0000.00816.49
7.4.280.0080.00016.64
7.4.270.0000.00816.51
7.4.260.0000.00816.67
7.4.250.0000.00716.41
7.4.240.0050.00316.56
7.4.230.0030.00316.79
7.4.220.0000.00716.68
7.4.210.0070.01116.65
7.4.200.0000.00716.76
7.4.160.0140.00716.54
7.4.130.0150.00416.77
7.4.120.0070.01716.67
7.4.110.0060.01516.68
7.4.100.0180.00016.53
7.4.90.0140.00316.55
7.4.80.0070.01019.39
7.4.70.0100.01016.66
7.4.60.0030.01316.56
7.4.50.0070.00316.43
7.4.40.0090.00916.64
7.4.00.0080.01015.16
7.3.330.0030.00613.37
7.3.320.0000.00613.38
7.3.310.0030.00316.43
7.3.300.0000.00816.48
7.3.290.0000.00716.44
7.3.280.0110.00816.45
7.3.260.0100.00916.51
7.3.240.0080.00916.60
7.3.230.0070.01016.66
7.3.210.0070.01116.63
7.3.200.0060.01116.39
7.3.190.0140.01016.39
7.3.180.0120.01216.66
7.3.170.0060.01216.46
7.3.160.0090.01316.54
7.3.120.0070.01014.77
7.3.110.0060.01014.90
7.3.100.0060.01015.11
7.3.90.0040.01114.96
7.3.80.0100.00614.95
7.3.70.0060.00314.89
7.3.60.0140.00014.86
7.3.50.0030.01314.55
7.3.40.0070.00514.82
7.3.30.0100.00214.70
7.3.20.0090.00615.86
7.3.10.0080.00515.48
7.3.00.0130.00815.81
7.2.330.0100.01316.67
7.2.320.0100.01316.61
7.2.310.0130.00416.86
7.2.300.0060.01016.85
7.2.290.0110.00716.73
7.2.250.0100.01015.24
7.2.240.0070.01314.90
7.2.230.0070.01015.44
7.2.220.0040.01215.39
7.2.210.0040.01115.34
7.2.200.0040.00815.25
7.2.190.0050.01215.27
7.2.180.0030.01315.17
7.2.170.0090.00615.21
7.2.160.0100.01314.77
7.2.150.0100.00615.11
7.2.140.0070.00715.23
7.2.130.0100.01015.20
7.2.120.0120.00815.18
7.2.110.0170.01115.20
7.2.100.0170.00915.28
7.2.90.0040.01115.07
7.2.80.0210.00915.05
7.2.70.0140.00315.10
7.2.60.0200.00515.26
7.2.50.0110.01514.99
7.2.40.0160.01015.20
7.2.30.0090.00915.12
7.2.20.0090.00914.93
7.2.10.0160.01015.30
7.2.00.0150.00315.21
7.1.330.0100.00316.04
7.1.320.0100.01015.93
7.1.310.0000.01215.89
7.1.300.0060.00915.48
7.1.290.0090.00915.89
7.1.280.0070.00714.93
7.1.270.0100.00414.97
7.1.260.0070.00714.92
7.1.250.0070.01113.64

preferences:
62.09 ms | 400 KiB | 5 Q