3v4l.org

run code in 200+ 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; 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); } } 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 isKind(){ $x = max(array_count_values($this->getValues())); if($x == 2){ echo "Two of a kind"; } else if($x == 3){ echo "Three of a kind"; } if($x == 4){ echo "Four of a kind"; } } } $h = new Hand('9s 9h 7d Js 10c'); $x = $h->isKind(); // var_dump($x);
based on tbSsC
Output for 7.1.25 - 7.3.4
Two of a kind