3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getSuitValue($card) { $result = 0; switch($card[1]) { case 'C' : $result *= 10; break; case 'H' : $result *= 100; break; case 'D' : $result *= 1000; break; default: $result *= 1; } return $result; } function getValue($card) { $result = 0; switch($card[0]) { case 'A' : $result += 1; break; case 'J' : $result += 11; break; case 'Q' : $result += 12; break; case 'K' : $result += 13; break; default: $result += (int)$card[0]; } return $result; } function isGreat($card1, $card2) { $val1 = getValue($card1); $val2 = getValue($card2); if ($val1 > $val2) { return true; } elseif ($val1 === $val2) { if (getSuitValue($card1) > getSuitValue($card2)) { return true; } } return false; } function mySort($arr) { for ($i = 1; $i < count($arr); $i++) { $x = $arr[$i]; for ($j = $i - 1; $j >= 0 && isGreat($arr[$j], $x); $j--) { $arr[$j + 1] = $arr[$j]; } // на оставшееся после сдвига место, ставим $a[$i] $arr[$j + 1] = $x; } return $arr; } function sort_cards($cards) { $array = explode(', ', $cards); $resultArr = mySort($array); return implode(', ', $resultArr); } echo sort_cards('1C, 5S, 4D'), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WOIKf
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   INIT_FCALL                                               'sort_cards'
          1        SEND_VAL                                                 '1C%2C+5S%2C+4D'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4        ECHO                                                     '%0A'
          5      > RETURN                                                   1

Function getsuitvalue:
Finding entry points
Branch analysis from position: 0
5 jumps found. (Code = 188) Position 1 = 11, Position 2 = 13, Position 3 = 15, Position 4 = 17, Position 5 = 4
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 15
Branch analysis from position: 13
Branch analysis from position: 11
filename:       /in/WOIKf
function name:  getSuitValue
number of ops:  21
compiled vars:  !0 = $card, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 0
    5     2        FETCH_DIM_R                                      ~3      !0, 1
          3      > SWITCH_STRING                                            ~3, [ 'C':->11, 'H':->13, 'D':->15, ], ->17
    6     4    >   CASE                                                     ~3, 'C'
          5      > JMPNZ                                                    ~4, ->11
    7     6    >   CASE                                                     ~3, 'H'
          7      > JMPNZ                                                    ~4, ->13
    8     8    >   CASE                                                     ~3, 'D'
          9      > JMPNZ                                                    ~4, ->15
         10    > > JMP                                                      ->17
    6    11    >   ASSIGN_OP                                     3          !1, 10
         12      > JMP                                                      ->18
    7    13    >   ASSIGN_OP                                     3          !1, 100
         14      > JMP                                                      ->18
    8    15    >   ASSIGN_OP                                     3          !1, 1000
         16      > JMP                                                      ->18
    9    17    >   ASSIGN_OP                                     3          !1, 1
         18    >   FREE                                                     ~3
   11    19      > RETURN                                                   !1
   12    20*     > RETURN                                                   null

End of function getsuitvalue

Function getvalue:
Finding entry points
Branch analysis from position: 0
6 jumps found. (Code = 188) Position 1 = 13, Position 2 = 15, Position 3 = 17, Position 4 = 19, Position 5 = 21, Position 6 = 4
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 19
Branch analysis from position: 17
Branch analysis from position: 15
Branch analysis from position: 13
filename:       /in/WOIKf
function name:  getValue
number of ops:  27
compiled vars:  !0 = $card, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, 0
   16     2        FETCH_DIM_R                                      ~3      !0, 0
          3      > SWITCH_STRING                                            ~3, [ 'A':->13, 'J':->15, 'Q':->17, 'K':->19, ], ->21
   17     4    >   CASE                                                     ~3, 'A'
          5      > JMPNZ                                                    ~4, ->13
   18     6    >   CASE                                                     ~3, 'J'
          7      > JMPNZ                                                    ~4, ->15
   19     8    >   CASE                                                     ~3, 'Q'
          9      > JMPNZ                                                    ~4, ->17
   20    10    >   CASE                                                     ~3, 'K'
         11      > JMPNZ                                                    ~4, ->19
         12    > > JMP                                                      ->21
   17    13    >   ASSIGN_OP                                     1          !1, 1
         14      > JMP                                                      ->24
   18    15    >   ASSIGN_OP                                     1          !1, 11
         16      > JMP                                                      ->24
   19    17    >   ASSIGN_OP                                     1          !1, 12
         18      > JMP                                                      ->24
   20    19    >   ASSIGN_OP                                     1          !1, 13
         20      > JMP                                                      ->24
   21    21    >   FETCH_DIM_R                                      ~9      !0, 0
         22        CAST                                          4  ~10     ~9
         23        ASSIGN_OP                                     1          !1, ~10
         24    >   FREE                                                     ~3
   23    25      > RETURN                                                   !1
   24    26*     > RETURN                                                   null

End of function getvalue

Function isgreat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/WOIKf
function name:  isGreat
number of ops:  27
compiled vars:  !0 = $card1, !1 = $card2, !2 = $val1, !3 = $val2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   27     2        INIT_FCALL                                               'getvalue'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !2, $4
   28     6        INIT_FCALL                                               'getvalue'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !3, $6
   29    10        IS_SMALLER                                               !3, !2
         11      > JMPZ                                                     ~8, ->14
   30    12    > > RETURN                                                   <true>
         13*       JMP                                                      ->25
   31    14    >   IS_IDENTICAL                                             !2, !3
         15      > JMPZ                                                     ~9, ->25
   32    16    >   INIT_FCALL                                               'getsuitvalue'
         17        SEND_VAR                                                 !0
         18        DO_FCALL                                      0  $10     
         19        INIT_FCALL                                               'getsuitvalue'
         20        SEND_VAR                                                 !1
         21        DO_FCALL                                      0  $11     
         22        IS_SMALLER                                               $11, $10
         23      > JMPZ                                                     ~12, ->25
   33    24    > > RETURN                                                   <true>
   37    25    > > RETURN                                                   <false>
   38    26*     > RETURN                                                   null

End of function isgreat

Function mysort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 3
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 8
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 3
Branch analysis from position: 29
Branch analysis from position: 3
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
Branch analysis from position: 21
Branch analysis from position: 21
filename:       /in/WOIKf
function name:  mySort
number of ops:  31
compiled vars:  !0 = $arr, !1 = $i, !2 = $x, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        ASSIGN                                                   !1, 1
          2      > JMP                                                      ->26
   42     3    >   FETCH_DIM_R                                      ~5      !0, !1
          4        ASSIGN                                                   !2, ~5
   43     5        SUB                                              ~7      !1, 1
          6        ASSIGN                                                   !3, ~7
          7      > JMP                                                      ->13
   44     8    >   ADD                                              ~9      !3, 1
          9        FETCH_DIM_R                                      ~11     !0, !3
         10        ASSIGN_DIM                                               !0, ~9
         11        OP_DATA                                                  ~11
   43    12        PRE_DEC                                                  !3
         13    >   IS_SMALLER_OR_EQUAL                              ~13     0, !3
         14      > JMPZ_EX                                          ~13     ~13, ->21
         15    >   INIT_FCALL                                               'isgreat'
         16        FETCH_DIM_R                                      ~14     !0, !3
         17        SEND_VAL                                                 ~14
         18        SEND_VAR                                                 !2
         19        DO_FCALL                                      0  $15     
         20        BOOL                                             ~13     $15
         21    > > JMPNZ                                                    ~13, ->8
   47    22    >   ADD                                              ~16     !3, 1
         23        ASSIGN_DIM                                               !0, ~16
         24        OP_DATA                                                  !2
   41    25        PRE_INC                                                  !1
         26    >   COUNT                                            ~19     !0
         27        IS_SMALLER                                               !1, ~19
         28      > JMPNZ                                                    ~20, ->3
   50    29    > > RETURN                                                   !0
   51    30*     > RETURN                                                   null

End of function mysort

Function sort_cards:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WOIKf
function name:  sort_cards
number of ops:  16
compiled vars:  !0 = $cards, !1 = $array, !2 = $resultArr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2C+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   55     6        INIT_FCALL                                               'mysort'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $5      
          9        ASSIGN                                                   !2, $5
   57    10        INIT_FCALL                                               'implode'
         11        SEND_VAL                                                 '%2C+'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $7      
         14      > RETURN                                                   $7
   58    15*     > RETURN                                                   null

End of function sort_cards

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.32 ms | 1415 KiB | 24 Q