PHP code example of simple-hacker / phpoker

1. Go to this page and download the library: Download simple-hacker/phpoker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simple-hacker / phpoker example snippets


use simplehacker\PHPoker\Hands\TexasHoldemHand;

$communityCards = '3hJdQdAdKd';
$holeCards = 'Td6s';

$hand = new TexasHoldemHand($communityCards, $holeCards);

$communityCards = '3hJdQdAdKd';
$communityCards = ['3h', 'Jd', 'Qd', 'Ad', 'Kd'];
$communityCards = [new Card('3h'), new Card('Jd'), new Card('Qd'), new Card('Ad'), new Card('Kd')];
$communityCards = [new Card('3h'), 'Jd', new Card('Qd'), 'Ad', new Card('Kd')];  // A mix of both

use simplehacker\PHPoker\Hands\TexasHoldemHand;

$communityCards = '3hJdQdAdKd';
$holeCards = 'Td6s';

$hand = new TexasHoldemHand($communityCards, $holeCards);

// Royal Flush, Ace to Ten of Diamonds
$hand->getDescription();

// AdKdQdJdTd
$hand->getShortDescription();

// 10
$hand->getHandRank();

// const ROYAL_FLUSH_RANK      = 10;
// const STRAIGHT_FLUSH_RANK   = 9;
// const FOUR_OF_A_KIND_RANK   = 8;
// const FULL_HOUSE_RANK       = 7;
// const FLUSH_RANK            = 6;
// const STRAIGHT_RANK         = 5;
// const THREE_OF_A_KIND_RANK  = 4;
// const TWO_PAIR_RANK         = 3;
// const ONE_PAIR_RANK         = 2;
// const HIGH_CARD_RANK        = 1;

// 11459770
$hand->getHandValue();

// Hand value is generated from converting Hand Rank and all Card values to a binary string, and converting back to base 10.  This ensures the best hand will always be the highest number

// As a short value where the first character is card value 23456789TJQKA,
// and the second character is card suit as shcd
new Card('As');

// Arguments for both value and suit
new Card('Ace', 'Spades');
new Card('A', 's');

// As numerical values
// Jack = 11, Queen = 12, King = 13, Ace = 1 or 14
// Clubs = 1, Diamonds = 2, Hearts = 3, Spades = 4
new Card(14, 4);

// Or any combination of the above
new Card('Ace', 's');
new Card(1, 'spades');