3v4l.org

run code in 300+ PHP versions simultaneously
<?php $regex = '^(?=.{5}$) .*? ( (?<high_straight>(?!.*(?<hscard>.).*(?P=hscard))[TJQKA]{5})| (?<straight>(?!.*(?<scard>.).*(?P=scard))(?:[A2345]{5}|[23456]{5}|[34567]{5}|[45678]{5}|[56789]{5}|[6789T]{5}|[789TJ]{5}|[89TJQ]{5}|[9TJQK]{5}))| (?<four_of_a_kind>.)(?:.*(?P=four_of_a_kind)){3}| (?<full_house>(?=.*(?<fh_card1>.)(?=(?:.*(?P=fh_card1)){2}))(?=.*(?<fh_card2>(?!(?P=fh_card1)).)(?=.*(?P=fh_card2))).+)| (?<three_of_a_kind>.)(?:.*(?P=three_of_a_kind)){2}| (?<two_pair>(?=.*(?<tp_card1>.)(?=(?P=tp_card1)))(?=.*(?<tp_card2>(?!(?P=tp_card1)).)(?=.*(?P=tp_card2))).+)| (?<two_of_a_kind>.).*(?P=two_of_a_kind) )'; $hands = array('AJKTQ', '43A52', 'AAKAA', '58888', '58585', 'AKKKA', '22333', 'AK9AA', '78444', '93233', '64886', '662TT', '67898', '432A4', 'KQA34', '34628'); foreach ($hands as $hand) { echo "$hand: "; preg_match_all("/$regex/x", $hand, $matches, PREG_SET_ORDER); if (!count($matches)) { // here you should check for a flush echo "high card"; } else { $matched_hand = array_filter($matches[0], function ($v, $k) { return !empty($v) && !is_numeric($k); }, ARRAY_FILTER_USE_BOTH); switch (key($matched_hand)) { case 'full_house': echo "full house {$matches[0]['fh_card1']} over {$matches[0]['fh_card2']}"; break; case 'two_pair': // here you should sort for the highest pair echo "two_pair {$matches[0]['tp_card1']} over {$matches[0]['tp_card2']}"; break; case 'four_of_a_kind': case 'three_of_a_kind': case 'two_of_a_kind': echo key($matched_hand) . " " . current($matched_hand); break; default: // here you should check for a straight flush or royal flush echo key($matched_hand); break; } } echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 82
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 82
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
7 jumps found. (Code = 188) Position 1 = 44, Position 2 = 54, Position 3 = 64, Position 4 = 64, Position 5 = 64, Position 6 = 74, Position 7 = 33
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
Branch analysis from position: 64
Branch analysis from position: 64
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 44
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 54
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 64
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 64
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 64
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
Branch analysis from position: 64
Branch analysis from position: 64
Branch analysis from position: 64
Branch analysis from position: 54
Branch analysis from position: 44
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
filename:       /in/s1Yo0
function name:  (null)
number of ops:  84
compiled vars:  !0 = $regex, !1 = $hands, !2 = $hand, !3 = $matches, !4 = $matched_hand
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5E%28%3F%3D.%7B5%7D%24%29%0A+++++++++++.%2A%3F%0A+++++++++++%28%0A++++++++++++%28%3F%3Chigh_straight%3E%28%3F%21.%2A%28%3F%3Chscard%3E.%29.%2A%28%3FP%3Dhscard%29%29%5BTJQKA%5D%7B5%7D%29%7C%0A++++++++++++%28%3F%3Cstraight%3E%28%3F%21.%2A%28%3F%3Cscard%3E.%29.%2A%28%3FP%3Dscard%29%29%28%3F%3A%5BA2345%5D%7B5%7D%7C%5B23456%5D%7B5%7D%7C%5B34567%5D%7B5%7D%7C%5B45678%5D%7B5%7D%7C%5B56789%5D%7B5%7D%7C%5B6789T%5D%7B5%7D%7C%5B789TJ%5D%7B5%7D%7C%5B89TJQ%5D%7B5%7D%7C%5B9TJQK%5D%7B5%7D%29%29%7C%0A++++++++++++%28%3F%3Cfour_of_a_kind%3E.%29%28%3F%3A.%2A%28%3FP%3Dfour_of_a_kind%29%29%7B3%7D%7C%0A++++++++++++%28%3F%3Cfull_house%3E%28%3F%3D.%2A%28%3F%3Cfh_card1%3E.%29%28%3F%3D%28%3F%3A.%2A%28%3FP%3Dfh_card1%29%29%7B2%7D%29%29%28%3F%3D.%2A%28%3F%3Cfh_card2%3E%28%3F%21%28%3FP%3Dfh_card1%29%29.%29%28%3F%3D.%2A%28%3FP%3Dfh_card2%29%29%29.%2B%29%7C%0A++++++++++++%28%3F%3Cthree_of_a_kind%3E.%29%28%3F%3A.%2A%28%3FP%3Dthree_of_a_kind%29%29%7B2%7D%7C%0A++++++++++++%28%3F%3Ctwo_pair%3E%28%3F%3D.%2A%28%3F%3Ctp_card1%3E.%29%28%3F%3D%28%3FP%3Dtp_card1%29%29%29%28%3F%3D.%2A%28%3F%3Ctp_card2%3E%28%3F%21%28%3FP%3Dtp_card1%29%29.%29%28%3F%3D.%2A%28%3FP%3Dtp_card2%29%29%29.%2B%29%7C%0A++++++++++++%28%3F%3Ctwo_of_a_kind%3E.%29.%2A%28%3FP%3Dtwo_of_a_kind%29%0A+++++++++++%29'
   15     1        ASSIGN                                                   !1, <array>
   19     2      > FE_RESET_R                                       $7      !1, ->82
          3    > > FE_FETCH_R                                               $7, !2, ->82
   20     4    >   NOP                                                      
          5        FAST_CONCAT                                      ~8      !2, '%3A+'
          6        ECHO                                                     ~8
   21     7        INIT_FCALL                                               'preg_match_all'
          8        ROPE_INIT                                     3  ~10     '%2F'
          9        ROPE_ADD                                      1  ~10     ~10, !0
         10        ROPE_END                                      2  ~9      ~10, '%2Fx'
         11        SEND_VAL                                                 ~9
         12        SEND_VAR                                                 !2
         13        SEND_REF                                                 !3
         14        SEND_VAL                                                 2
         15        DO_ICALL                                                 
   22    16        COUNT                                            ~13     !3
         17        BOOL_NOT                                         ~14     ~13
         18      > JMPZ                                                     ~14, ->21
   24    19    >   ECHO                                                     'high+card'
   22    20      > JMP                                                      ->80
   27    21    >   INIT_FCALL                                               'array_filter'
         22        FETCH_DIM_R                                      ~15     !3, 0
         23        SEND_VAL                                                 ~15
         24        DECLARE_LAMBDA_FUNCTION                          ~16     [0]
   29    25        SEND_VAL                                                 ~16
         26        SEND_VAL                                                 1
   27    27        DO_ICALL                                         $17     
         28        ASSIGN                                                   !4, $17
   30    29        INIT_FCALL                                               'key'
         30        SEND_VAR                                                 !4
         31        DO_ICALL                                         $19     
         32      > SWITCH_STRING                                            $19, [ 'full_house':->44, 'two_pair':->54, 'four_of_a_kind':->64, 'three_of_a_kind':->64, 'two_of_a_kind':->64, ], ->74
   31    33    >   CASE                                                     $19, 'full_house'
         34      > JMPNZ                                                    ~20, ->44
   34    35    >   CASE                                                     $19, 'two_pair'
         36      > JMPNZ                                                    ~20, ->54
   38    37    >   CASE                                                     $19, 'four_of_a_kind'
         38      > JMPNZ                                                    ~20, ->64
   39    39    >   CASE                                                     $19, 'three_of_a_kind'
         40      > JMPNZ                                                    ~20, ->64
   40    41    >   CASE                                                     $19, 'two_of_a_kind'
         42      > JMPNZ                                                    ~20, ->64
         43    > > JMP                                                      ->74
   32    44    >   ROPE_INIT                                     4  ~26     'full+house+'
         45        FETCH_DIM_R                                      ~21     !3, 0
         46        FETCH_DIM_R                                      ~22     ~21, 'fh_card1'
         47        ROPE_ADD                                      1  ~26     ~26, ~22
         48        ROPE_ADD                                      2  ~26     ~26, '+over+'
         49        FETCH_DIM_R                                      ~23     !3, 0
         50        FETCH_DIM_R                                      ~24     ~23, 'fh_card2'
         51        ROPE_END                                      3  ~25     ~26, ~24
         52        ECHO                                                     ~25
   33    53      > JMP                                                      ->79
   36    54    >   ROPE_INIT                                     4  ~33     'two_pair+'
         55        FETCH_DIM_R                                      ~28     !3, 0
         56        FETCH_DIM_R                                      ~29     ~28, 'tp_card1'
         57        ROPE_ADD                                      1  ~33     ~33, ~29
         58        ROPE_ADD                                      2  ~33     ~33, '+over+'
         59        FETCH_DIM_R                                      ~30     !3, 0
         60        FETCH_DIM_R                                      ~31     ~30, 'tp_card2'
         61        ROPE_END                                      3  ~32     ~33, ~31
         62        ECHO                                                     ~32
   37    63      > JMP                                                      ->79
   41    64    >   INIT_FCALL                                               'key'
         65        SEND_VAR                                                 !4
         66        DO_ICALL                                         $35     
         67        CONCAT                                           ~36     $35, '+'
         68        INIT_FCALL                                               'current'
         69        SEND_VAR                                                 !4
         70        DO_ICALL                                         $37     
         71        CONCAT                                           ~38     ~36, $37
         72        ECHO                                                     ~38
   42    73      > JMP                                                      ->79
   45    74    >   INIT_FCALL                                               'key'
         75        SEND_VAR                                                 !4
         76        DO_ICALL                                         $39     
         77        ECHO                                                     $39
   46    78      > JMP                                                      ->79
         79    >   FREE                                                     $19
   49    80    >   ECHO                                                     '%0A'
   19    81      > JMP                                                      ->3
         82    >   FE_FREE                                                  $7
   50    83      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/s1Yo0
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $v, !1 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        ISSET_ISEMPTY_CV                                 ~2      !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ_EX                                          ~3      ~3, ->10
          5    >   INIT_FCALL                                               'is_numeric'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $4      
          8        BOOL_NOT                                         ~5      $4
          9        BOOL                                             ~3      ~5
         10    > > RETURN                                                   ~3
   29    11*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
245.52 ms | 1017 KiB | 18 Q