function hand_type($hand) { $ranks = []; $suits = []; for ($rank = 0; $rank < RANK_COUNT; $rank++) { $ranks[$rank] = 0; } for ($suit = 0; $suit < SUIT_COUNT; $suit++) { $suits[$suit] = 0; } foreach ($hand as $card) { $ranks[$card[RANK_FIELD]]++; $suits[$card[SUIT_FIELD]]++; } // echo '<pre>'; // print_r($ranks); // print_r($suits); // echo '</pre>'; $flush = is_flush($suits); $straight = is_straight($ranks); $royal = is_royal($ranks); if ($flush && $royal) { return ROYAL_FLUSH; } elseif ($flush && $straight) { return STRAIGHT_FLUSH; } elseif (is_quads($ranks)) { return QUADS; } elseif (is_boat($ranks)) { return BOAT; } elseif ($flush) { return FLUSH; } elseif ($straight) { return STRAIGHT; } elseif (is_trips($ranks)) { return TRIPS; } elseif (is_two_pair($ranks)) { return TWO_PAIR; } elseif (is_pair_jacks($ranks)) { return PAIR_JACKS; } elseif (is_pair($ranks)) { return LOW_PAIR; } else { return NOTHING; } }
function checkrank($data) { //set the access for globals global $arCardRanks; // lets get all the digits first $digits = array(); foreach ($data as $card) { $digits[] = $card[0]; } // then the suites $suites = array(); foreach ($data as $card) { $suites[] = $card[1]; } // lets run all the function to check for combination if (is_royalFlush($digits, $suites)) { $rank = 9; } elseif (is_straightFlush($digits, $suites)) { $rank = 8; } elseif (is_fourOfAKind($digits)) { $rank = 7; } elseif (is_fullHouse($digits)) { $rank = 6; } elseif (is_flush($suites)) { $rank = 5; } elseif (is_straight($digits)) { $rank = 4; } elseif (is_threeOfAKind($digits)) { $rank = 3; } elseif (is_twoPairs($digits)) { $rank = 2; } elseif (is_onePair($digits)) { $rank = 1; } else { $rank = 0; } return $rank; // echo "<br />"; // echo "Combination: ". $arCardRanks[$rank]; // echo "<br>"; // print_r($digits); // echo "<br>"; // print_r($suites); }