3v4l.org

run code in 300+ PHP versions simultaneously
<?php function compareCombinations($toFind, $toTry){ $nb = 4; $goodPlace = 0; $wrongPlace = 0; $toFind = str_split($toFind); $toTry = str_split($toTry); var_dump($toFind, $toTry); //Look for good places for($i = 0; $i < $nb; $i++){ if($toFind[$i] === $toTry[$i]){ $goodPlace++; } } //Look for wrong places for($i = 0; $i < $nb; $i++){ for($j = 0; $j < $nb; $j++){ if($i == $j){ continue; } if($toTry[$i] === $toFind[$j]){ $wrongPlace++; continue 2; } } } return array( 'good' => $goodPlace, 'wrong' => $wrongPlace, 'absent' => $nb - $goodPlace - $wrongPlace ); } foreach(array('0000' => '0001') as $find => $try){ $r = compareCombinations($find,$try); var_dump(array( 'find' => $find, 'try' => $try ) + $r); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 15
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 15
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/eGLZp
function name:  (null)
number of ops:  17
compiled vars:  !0 = $try, !1 = $find, !2 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E > > FE_RESET_R                                       $3      <array>, ->15
          1    > > FE_FETCH_R                                       ~4      $3, !0, ->15
          2    >   ASSIGN                                                   !1, ~4
   40     3        INIT_FCALL                                               'comparecombinations'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !2, $6
   41     8        INIT_FCALL                                               'var_dump'
   42     9        INIT_ARRAY                                       ~8      !1, 'find'
   43    10        ADD_ARRAY_ELEMENT                                ~8      !0, 'try'
   44    11        ADD                                              ~9      ~8, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   39    14      > JMP                                                      ->1
         15    >   FE_FREE                                                  $3
   45    16      > RETURN                                                   1

Function comparecombinations:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 19
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 29
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 31
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 29
Branch analysis from position: 46
Branch analysis from position: 29
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 31
Branch analysis from position: 43
Branch analysis from position: 31
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
Branch analysis from position: 40
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 19
Branch analysis from position: 27
Branch analysis from position: 19
Branch analysis from position: 24
filename:       /in/eGLZp
function name:  compareCombinations
number of ops:  53
compiled vars:  !0 = $toFind, !1 = $toTry, !2 = $nb, !3 = $goodPlace, !4 = $wrongPlace, !5 = $i, !6 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, 4
    4     3        ASSIGN                                                   !3, 0
    5     4        ASSIGN                                                   !4, 0
    7     5        INIT_FCALL                                               'str_split'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $10     
          8        ASSIGN                                                   !0, $10
    8     9        INIT_FCALL                                               'str_split'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !1, $12
   10    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
   13    17        ASSIGN                                                   !5, 0
         18      > JMP                                                      ->25
   14    19    >   FETCH_DIM_R                                      ~16     !0, !5
         20        FETCH_DIM_R                                      ~17     !1, !5
         21        IS_IDENTICAL                                             ~16, ~17
         22      > JMPZ                                                     ~18, ->24
   15    23    >   PRE_INC                                                  !3
   13    24    >   PRE_INC                                                  !5
         25    >   IS_SMALLER                                               !5, !2
         26      > JMPNZ                                                    ~21, ->19
   20    27    >   ASSIGN                                                   !5, 0
         28      > JMP                                                      ->44
   21    29    >   ASSIGN                                                   !6, 0
         30      > JMP                                                      ->41
   22    31    >   IS_EQUAL                                                 !5, !6
         32      > JMPZ                                                     ~24, ->34
   23    33    > > JMP                                                      ->40
   25    34    >   FETCH_DIM_R                                      ~25     !1, !5
         35        FETCH_DIM_R                                      ~26     !0, !6
         36        IS_IDENTICAL                                             ~25, ~26
         37      > JMPZ                                                     ~27, ->40
   26    38    >   PRE_INC                                                  !4
   27    39      > JMP                                                      ->43
   21    40    >   PRE_INC                                                  !6
         41    >   IS_SMALLER                                               !6, !2
         42      > JMPNZ                                                    ~30, ->31
   20    43    >   PRE_INC                                                  !5
         44    >   IS_SMALLER                                               !5, !2
         45      > JMPNZ                                                    ~32, ->29
   33    46    >   INIT_ARRAY                                       ~33     !3, 'good'
   34    47        ADD_ARRAY_ELEMENT                                ~33     !4, 'wrong'
   35    48        SUB                                              ~34     !2, !3
         49        SUB                                              ~35     ~34, !4
         50        ADD_ARRAY_ELEMENT                                ~33     ~35, 'absent'
         51      > RETURN                                                   ~33
   37    52*     > RETURN                                                   null

End of function comparecombinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.6 ms | 1407 KiB | 18 Q