3v4l.org

run code in 300+ PHP versions simultaneously
<?php $states = ["AGGR", "NOMOVE", "COWARD", "NOATTSHINSU", "NOATTCHUNJO", "NOATTJINNO", "ATTMOB", "BERSERK", "STONESKIN", "GODSPEED", "DEATHBLOW", "REVIVE"]; $samples = ["AGGR", "AGGR,BERSERK", "AGGR,BERSERK,DEATHBLOW,REVIVE", "AGGR,BERSERK,STONESKIN", "AGGR,BERSERK,STONESKIN,DEATHBLOW", "AGGR,BERSERK,STONESKIN,DEATHBLOW,REVIVE", "AGGR,BERSERK,STONESKIN,DEATHBLOW,REVIVE", "AGGR,DEATHBLOW", "AGGR,GODSPEED", "AGGR,GODSPEED", "AGGR,NOATTCHUNJO", "AGGR,NOATTJINNO", "AGGR,NOATTSHINSU", "AGGR,NOMOVE", "AGGR,REVIVE", "AGGR,STONESKIN", "BERSERK", "BERSERK,STONESKIN", "COWARD", "NOMOVE", "AGGR,NOMOVE,BERSERK,GODSPEED,DEATHBLOW", "NOMOVE,STONESKIN", "NOMOVE,STONESKIN", "REVIVE"]; function states2flags($userStates, $allStates) { $userFlags = 0; $bit = 1; foreach ($allStates as $state) { if (in_array($state, $userStates)) { $userFlags += $bit; } $bit <<= 1; } return $userFlags; } function flags2states($userFlags, $allStates) { $userStates = []; $bit = 1; foreach ($allStates as $state) { if ($userFlags & $bit) { $userStates[] = $state; } $bit <<= 1; } return $userStates; } foreach($samples as $sample) { $sampleStates = explode(",", $sample); $sampleFlags = states2flags($sampleStates, $states); $reverseStates = flags2states($sampleFlags, $states); $reverseFlags = states2flags($reverseStates, $states); $textColor = (count(array_diff($sampleStates, $reverseStates)) > 0) ? "red" : "green"; echo '<a class="' . $textColor . '">' . $textColor . ' Original Data - <b>' . $sample . ' [' . $sampleFlags . ']</b> - Reverse Data - <b>' . implode(",", flags2states($sampleFlags, $states)) . ' ['.$reverseFlags. ']</b><br>'; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 57
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 57
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
filename:       /in/OPdDW
function name:  (null)
number of ops:  59
compiled vars:  !0 = $states, !1 = $samples, !2 = $sample, !3 = $sampleStates, !4 = $sampleFlags, !5 = $reverseStates, !6 = $reverseFlags, !7 = $textColor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, <array>
   67     2      > FE_RESET_R                                       $10     !1, ->57
          3    > > FE_FETCH_R                                               $10, !2, ->57
   68     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%2C'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $11     
          8        ASSIGN                                                   !3, $11
   69     9        INIT_FCALL                                               'states2flags'
         10        SEND_VAR                                                 !3
         11        SEND_VAR                                                 !0
         12        DO_FCALL                                      0  $13     
         13        ASSIGN                                                   !4, $13
   70    14        INIT_FCALL                                               'flags2states'
         15        SEND_VAR                                                 !4
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0  $15     
         18        ASSIGN                                                   !5, $15
   71    19        INIT_FCALL                                               'states2flags'
         20        SEND_VAR                                                 !5
         21        SEND_VAR                                                 !0
         22        DO_FCALL                                      0  $17     
         23        ASSIGN                                                   !6, $17
   72    24        INIT_FCALL                                               'array_diff'
         25        SEND_VAR                                                 !3
         26        SEND_VAR                                                 !5
         27        DO_ICALL                                         $19     
         28        COUNT                                            ~20     $19
         29        IS_SMALLER                                               0, ~20
         30      > JMPZ                                                     ~21, ->33
         31    >   QM_ASSIGN                                        ~22     'red'
         32      > JMP                                                      ->34
         33    >   QM_ASSIGN                                        ~22     'green'
         34    >   ASSIGN                                                   !7, ~22
   73    35        CONCAT                                           ~24     '%3Ca+class%3D%22', !7
         36        CONCAT                                           ~25     ~24, '%22%3E'
         37        CONCAT                                           ~26     ~25, !7
         38        CONCAT                                           ~27     ~26, '+Original+Data+-+%3Cb%3E'
         39        CONCAT                                           ~28     ~27, !2
   74    40        CONCAT                                           ~29     ~28, '+%5B'
         41        CONCAT                                           ~30     ~29, !4
         42        CONCAT                                           ~31     ~30, '%5D%3C%2Fb%3E+-+Reverse+Data+-+%3Cb%3E'
   75    43        INIT_FCALL                                               'implode'
         44        SEND_VAL                                                 '%2C'
         45        INIT_FCALL                                               'flags2states'
         46        SEND_VAR                                                 !4
         47        SEND_VAR                                                 !0
         48        DO_FCALL                                      0  $32     
         49        SEND_VAR                                                 $32
         50        DO_ICALL                                         $33     
         51        CONCAT                                           ~34     ~31, $33
         52        CONCAT                                           ~35     ~34, '+%5B'
         53        CONCAT                                           ~36     ~35, !6
         54        CONCAT                                           ~37     ~36, '%5D%3C%2Fb%3E%3Cbr%3E'
         55        ECHO                                                     ~37
   67    56      > JMP                                                      ->3
         57    >   FE_FREE                                                  $10
   76    58      > RETURN                                                   1

Function states2flags:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 12
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/OPdDW
function name:  states2flags
number of ops:  17
compiled vars:  !0 = $userStates, !1 = $allStates, !2 = $userFlags, !3 = $bit, !4 = $state
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   43     2        ASSIGN                                                   !2, 0
   44     3        ASSIGN                                                   !3, 1
   45     4      > FE_RESET_R                                       $7      !1, ->14
          5    > > FE_FETCH_R                                               $7, !4, ->14
   46     6    >   INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !4
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $8      
         10      > JMPZ                                                     $8, ->12
   47    11    >   ASSIGN_OP                                     1          !2, !3
   49    12    >   ASSIGN_OP                                     6          !3, 1
   45    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $7
   51    15      > RETURN                                                   !2
   52    16*     > RETURN                                                   null

End of function states2flags

Function flags2states:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 10
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/OPdDW
function name:  flags2states
number of ops:  15
compiled vars:  !0 = $userFlags, !1 = $allStates, !2 = $userStates, !3 = $bit, !4 = $state
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   56     2        ASSIGN                                                   !2, <array>
   57     3        ASSIGN                                                   !3, 1
   58     4      > FE_RESET_R                                       $7      !1, ->12
          5    > > FE_FETCH_R                                               $7, !4, ->12
   59     6    >   BW_AND                                           ~8      !0, !3
          7      > JMPZ                                                     ~8, ->10
   60     8    >   ASSIGN_DIM                                               !2
          9        OP_DATA                                                  !4
   62    10    >   ASSIGN_OP                                     6          !3, 1
   58    11      > JMP                                                      ->5
         12    >   FE_FREE                                                  $7
   64    13      > RETURN                                                   !2
   65    14*     > RETURN                                                   null

End of function flags2states

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.78 ms | 1025 KiB | 21 Q