PHP code example of bourdeau / handevaluator-bundle

1. Go to this page and download the library: Download bourdeau/handevaluator-bundle 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/ */

    

bourdeau / handevaluator-bundle example snippets

 php


// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Bourdeau\Bundle\HandEvaluatorBundle\BourdeauBundleHandEvaluatorBundle(),
    ];
    // ...
}
 php

// Path/To/Your/Controller
$winnerFinder = $this->container->get('bourdeau_bundle_hand_evaluator.winnerfinder');
$players = [
    'John'   => [QH, 2S, QS, JH, 5D, KH, 2H],
    'David'  => [9S, 2D, QS, JH, 5D, KH, 2H],
    'Robert' => [QD, QC, QS, JH, 5D, KH, 2H],
]

$result = $handFinder->findAWinner($players);

// $result will output:
│ array(2) {
│   ["winners"]=>
│   array(1) {
│     ["Robert"]=>
│     array(4) {
│       ["hand_name"]=>
│       string(15) "Three of a kind"
│       ["hand_rank"]=>
│       int(4)
│       ["card_rank"]=>
│       int(11)
│       ["cards"]=>
│       array(3) {
│         [0]=>
│         string(2) "QD"
│         [1]=>
│         string(2) "QC"
│         [2]=>
│         string(2) "QS"
│       }
│     }
│   }
│   ["other_players"]=>
│   array(2) {
│     ["John"]=>
│     array(4) {
│       ["hand_name"]=>
│       string(9) "Two Pairs"
│       ["hand_rank"]=>
│       int(3)
│       ["card_rank"]=>
│       int(11)
│       ["cards"]=>
│       array(4) {
│         [0]=>
│         string(2) "QH"
│         [1]=>
│         string(2) "QS"
│         [2]=>
│         string(2) "2S"
│         [3]=>
│         string(2) "2H"
│       }
│     }
│     ["David"]=>
│     array(4) {
│       ["hand_name"]=>
│       string(8) "One Pair"
│       ["hand_rank"]=>
│       int(2)
│       ["card_rank"]=>
│       int(1)
│       ["cards"]=>
│       array(2) {
│         [0]=>
│         string(2) "2D"
│         [1]=>
│         string(2) "2H"
│       }
│     }
│   }
│ }