3v4l.org

run code in 300+ PHP versions simultaneously
<?php function prepareArray($str) { $onlyLowerLetters = preg_replace('/[^a-z]/', '', strtolower($str)); $stringArray = str_split(str_replace(' ', '', $onlyLowerLetters)); $uniqueArray = array_unique($stringArray); $countsArray = []; foreach ($uniqueArray as $letter) { $countsArray[$letter] = substr_count($onlyLowerLetters, $letter); } unset($letter); foreach ($countsArray as $k => $v) { if ($v === 1) unset($countsArray[$k]); } ksort($countsArray); reset($countsArray); return $countsArray; } function getIntersect($a1, $a2) { $ar = array_intersect($a1, $a2); $intersect = []; foreach ($ar as $k => $v) { $intersect[$k] = $v; } return $intersect; } function compareArrays($a1, $a2) { // var_export($a1); // echo "\n"; // var_export($a2); // echo "\n"; $resultArray = []; foreach ($a1 as $k => $v) { $resultArray[$k][0] = $v; if (isset($a2[$k]) && $a1[$k] > $a2[$k]) { $resultArray[$k][0] = $v; } } foreach ($a2 as $k => $v) { $resultArray[$k][1] = $v; if (isset($a1[$k]) && $a1[$k] < $a2[$k]) { $resultArray[$k][1] = $v; } } return arsort($resultArray); } function mix($s1, $s2) { $s1Prepared = prepareArray($s1); $s2Prepared = prepareArray($s2); var_export($s1Prepared); echo "\n"; var_export($s2Prepared); echo "\n"; $intersectArray = getIntersect($s1Prepared, $s2Prepared); // var_export($intersectArray); // echo "\n"; $diffArray = compareArrays(array_diff_key($s1Prepared, $intersectArray), array_diff_key($s2Prepared, $intersectArray)); var_export($diffArray); echo "\n"; // $allLetters = array_merge($diffArray, $intersectArray); // var_export($allLetters); } mix("Are they here", "yes, they are here");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ppOvs
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_FCALL                                               'mix'
          1        SEND_VAL                                                 'Are+they+here'
          2        SEND_VAL                                                 'yes%2C+they+are+here'
          3        DO_FCALL                                      0          
          4      > RETURN                                                   1

Function preparearray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 42
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 41
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 33
filename:       /in/ppOvs
function name:  prepareArray
number of ops:  51
compiled vars:  !0 = $str, !1 = $onlyLowerLetters, !2 = $stringArray, !3 = $uniqueArray, !4 = $countsArray, !5 = $letter, !6 = $v, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5Ea-z%5D%2F'
          3        SEND_VAL                                                 ''
          4        INIT_FCALL                                               'strtolower'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $8      
          7        SEND_VAR                                                 $8
          8        DO_ICALL                                         $9      
          9        ASSIGN                                                   !1, $9
    5    10        INIT_FCALL                                               'str_split'
         11        INIT_FCALL                                               'str_replace'
         12        SEND_VAL                                                 '+'
         13        SEND_VAL                                                 ''
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $11     
         16        SEND_VAR                                                 $11
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !2, $12
    7    19        INIT_FCALL                                               'array_unique'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $14     
         22        ASSIGN                                                   !3, $14
    9    23        ASSIGN                                                   !4, <array>
   10    24      > FE_RESET_R                                       $17     !3, ->33
         25    > > FE_FETCH_R                                               $17, !5, ->33
   11    26    >   INIT_FCALL                                               'substr_count'
         27        SEND_VAR                                                 !1
         28        SEND_VAR                                                 !5
         29        DO_ICALL                                         $19     
         30        ASSIGN_DIM                                               !4, !5
         31        OP_DATA                                                  $19
   10    32      > JMP                                                      ->25
         33    >   FE_FREE                                                  $17
   13    34        UNSET_CV                                                 !5
   15    35      > FE_RESET_R                                       $20     !4, ->42
         36    > > FE_FETCH_R                                       ~21     $20, !6, ->42
         37    >   ASSIGN                                                   !7, ~21
   16    38        IS_IDENTICAL                                             !6, 1
         39      > JMPZ                                                     ~23, ->41
         40    >   UNSET_DIM                                                !4, !7
   15    41    > > JMP                                                      ->36
         42    >   FE_FREE                                                  $20
   18    43        INIT_FCALL                                               'ksort'
         44        SEND_REF                                                 !4
         45        DO_ICALL                                                 
   19    46        INIT_FCALL                                               'reset'
         47        SEND_REF                                                 !4
         48        DO_ICALL                                                 
   20    49      > RETURN                                                   !4
   21    50*     > RETURN                                                   null

End of function preparearray

Function getintersect:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/ppOvs
function name:  getIntersect
number of ops:  17
compiled vars:  !0 = $a1, !1 = $a2, !2 = $ar, !3 = $intersect, !4 = $v, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2        INIT_FCALL                                               'array_intersect'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !2, $6
   25     7        ASSIGN                                                   !3, <array>
   26     8      > FE_RESET_R                                       $9      !2, ->14
          9    > > FE_FETCH_R                                       ~10     $9, !4, ->14
         10    >   ASSIGN                                                   !5, ~10
   27    11        ASSIGN_DIM                                               !3, !5
         12        OP_DATA                                                  !4
   26    13      > JMP                                                      ->9
         14    >   FE_FREE                                                  $9
   29    15      > RETURN                                                   !3
   30    16*     > RETURN                                                   null

End of function getintersect

Function comparearrays:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 15
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 38
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 38
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 37
Branch analysis from position: 33
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 20
filename:       /in/ppOvs
function name:  compareArrays
number of ops:  44
compiled vars:  !0 = $a1, !1 = $a2, !2 = $resultArray, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2        ASSIGN                                                   !2, <array>
   39     3      > FE_RESET_R                                       $6      !0, ->20
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->20
          5    >   ASSIGN                                                   !4, ~7
   40     6        FETCH_DIM_W                                      $9      !2, !4
          7        ASSIGN_DIM                                               $9, 0
          8        OP_DATA                                                  !3
   41     9        ISSET_ISEMPTY_DIM_OBJ                         0  ~11     !1, !4
         10      > JMPZ_EX                                          ~11     ~11, ->15
         11    >   FETCH_DIM_R                                      ~12     !0, !4
         12        FETCH_DIM_R                                      ~13     !1, !4
         13        IS_SMALLER                                       ~14     ~13, ~12
         14        BOOL                                             ~11     ~14
         15    > > JMPZ                                                     ~11, ->19
   42    16    >   FETCH_DIM_W                                      $15     !2, !4
         17        ASSIGN_DIM                                               $15, 0
         18        OP_DATA                                                  !3
   39    19    > > JMP                                                      ->4
         20    >   FE_FREE                                                  $6
   46    21      > FE_RESET_R                                       $17     !1, ->38
         22    > > FE_FETCH_R                                       ~18     $17, !3, ->38
         23    >   ASSIGN                                                   !4, ~18
   47    24        FETCH_DIM_W                                      $20     !2, !4
         25        ASSIGN_DIM                                               $20, 1
         26        OP_DATA                                                  !3
   48    27        ISSET_ISEMPTY_DIM_OBJ                         0  ~22     !0, !4
         28      > JMPZ_EX                                          ~22     ~22, ->33
         29    >   FETCH_DIM_R                                      ~23     !0, !4
         30        FETCH_DIM_R                                      ~24     !1, !4
         31        IS_SMALLER                                       ~25     ~23, ~24
         32        BOOL                                             ~22     ~25
         33    > > JMPZ                                                     ~22, ->37
   49    34    >   FETCH_DIM_W                                      $26     !2, !4
         35        ASSIGN_DIM                                               $26, 1
         36        OP_DATA                                                  !3
   46    37    > > JMP                                                      ->22
         38    >   FE_FREE                                                  $17
   53    39        INIT_FCALL                                               'arsort'
         40        SEND_REF                                                 !2
         41        DO_ICALL                                         $28     
         42      > RETURN                                                   $28
   54    43*     > RETURN                                                   null

End of function comparearrays

Function mix:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ppOvs
function name:  mix
number of ops:  41
compiled vars:  !0 = $s1, !1 = $s2, !2 = $s1Prepared, !3 = $s2Prepared, !4 = $intersectArray, !5 = $diffArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   57     2        INIT_FCALL                                               'preparearray'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !2, $6
   58     6        INIT_FCALL                                               'preparearray'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !3, $8
   60    10        INIT_FCALL                                               'var_export'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
   61    13        ECHO                                                     '%0A'
   62    14        INIT_FCALL                                               'var_export'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
   63    17        ECHO                                                     '%0A'
   65    18        INIT_FCALL                                               'getintersect'
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !3
         21        DO_FCALL                                      0  $12     
         22        ASSIGN                                                   !4, $12
   70    23        INIT_FCALL                                               'comparearrays'
         24        INIT_FCALL                                               'array_diff_key'
         25        SEND_VAR                                                 !2
         26        SEND_VAR                                                 !4
         27        DO_ICALL                                         $14     
         28        SEND_VAR                                                 $14
         29        INIT_FCALL                                               'array_diff_key'
         30        SEND_VAR                                                 !3
         31        SEND_VAR                                                 !4
         32        DO_ICALL                                         $15     
         33        SEND_VAR                                                 $15
         34        DO_FCALL                                      0  $16     
         35        ASSIGN                                                   !5, $16
   72    36        INIT_FCALL                                               'var_export'
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                                 
   73    39        ECHO                                                     '%0A'
   77    40      > RETURN                                                   null

End of function mix

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.7 ms | 1415 KiB | 42 Q