Poker Hand Evaluator (Texas Hold 'em Algorithm 7-Card)

Poker Hand Evaluator (Texas Hold 'em Algorithm 7-Card)

Released 5 years ago , Last update 3 years ago

Calculates the best possible Poker hand of 5 cards out of the 7 cards possible in Texas Hold 'em. Lightweight. Simplistic. Elegant...

Poker made easy

Creating a poker game is both fun and complex. When it comes to working out the best 5 card hand out of the 7 cards available, the only factor left is complexity. There are a multitude of scenarios that need to be accounted for and after a few thousand lines of code, you may be wishing somebody had already written the algorithm for you.

Well, today is your lucky day.

  • Calculates best possible 5 card hand out of 7 cards
  • Gives the hand an absolute numerical score. Higher score = better hand
  • Numerical score considers every card in the hand
  • Provides detailed information on the 5 cards that form the hand
  • Load in multiple users (with 2 pocket cards each) along with the 5 community cards to do a complete end-game calculation
  • Includes a visualised demonstrator with debugging

Let's see what all the fuss is about...



  • 5 1
  • 4 0
  • 3 0
  • 2 0
  • 1 0
1 Reviews Read Reviews


14 day 14-day money-back guarantee


Basic License

  • Perpetual license

  • 1 site, 1 server

  • No distribution (hosted use only)

  • Commercial use

  • 6 months support


This class works in two ways. You can either feed a single set of 7 cards to receive an analysis of the best 5 card hand, which cards were used an most importantly a numerical score for the quality of the hand which can be used to directly compare multiple hands.

First, let's collect a list of the 7 cards available, including both pocket cards and community cards.

Step 1: Load in the cards

alt text

Let's suppose these are our cards....

$cards = array (
            "A_HEARTS","3_SPADES", //2 Pocket cards
            "8_CLUBS","9_CLUBS","3_HEARTS", "J_SPADES","4_DIAMONDS" //5 Community cards

Now let's see what the computer has to say

$poker = new PokerHandEvaluator();

Step 2: Review the results

alt text

$poker->displayableRank() = One Pair

As soon as we $poker->calculateRank(), everything is calculated. The debug cards feature will show us visually what is calculated, just so we can check our code is running smoothly.

The best 5 cards and all further information is presented in an array $poker->hand_information

$poker->hand_information = 
    [CARD_IDS] => Array
            [0] => 2
            [1] => 5
            [2] => 1
            [3] => 6
            [4] => 4

    [CARD_NAMES] => Array
            [0] => 3_SPADES
            [1] => 3_HEARTS
            [2] => A_HEARTS
            [3] => J_SPADES
            [4] => 9_CLUBS

    [NUMERIC_RANK] => 1
    [DISPLAYABLE_RANK] => One Pair
    [SCORE] => 20314110900

The card IDs are array keys based on the order they were loaded in at the start with $poker->loadCards(). [1] = First card loaded, and so on.

Card information is stored in the $poker->cards array based on ID. In this example, $poker->cards[1] was of course our first card; The Ace of Hearts.

[1] => Array
        [ID] => 1
        [PUREID] => 1
        [NUMBER] => 1
        [SUIT] => HEARTS
        [ORDER_RANK] => 4
        [INPUT] => A_HEARTS

Yep. One Pair looks right to me. Good job, Algorithm!

You can use $poker->hand_information['SCORE'] to compare multiple players and see who won. Simples

Step 3: Have a beer

The algorithm is that easy and you just saved dozens of development hours without writing boring algorithms.

Have a beer, you've earnt it.

2 licenses, starting from From » $49.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.

Or enter your name and Email
No comments have been posted yet.