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]); } arsort($countsArray); // reset($countsArray); return $countsArray; } function getIntersect($a1, $a2) { $ar = array_intersect_assoc($a1, $a2); $intersect = []; foreach ($ar as $k => $v) { $intersect[$k] = $v; } return $intersect; } function compareArrays($a1, $a2) { // var_export($a1); // var_export($a2); $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 $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"; foreach ($intersectArray as $letter=>$number) { $resultArray[$letter][2] = $number; } $resultArray = $diffArray + $resultArray; var_export($resultArray); echo "\n"; $str = []; foreach ($resultArray as $letter=>$allNumbers) { if ( (isset($allNumbers[0], $allNumbers[1]) && ($allNumbers[0] > $allNumbers[1]) ) || ( isset($allNumbers[0]) && !isset($allNumbers[1]) ) ) { $str[$allNumbers[0]]['letter'] = $letter; $str[$allNumbers[0]]['string'] = '1'; //$str[] = '1:' . str_repeat($letter, $allNumbers[0]); } if ( (isset($allNumbers[0], $allNumbers[1]) && ($allNumbers[0] < $allNumbers[1]) ) || ( isset($allNumbers[1]) && !isset($allNumbers[0]) ) ) { $str[$allNumbers[1]]['letter'] = $letter; $str[$allNumbers[1]]['string'] = '2'; // $str[] = '2:' . str_repeat($letter, $allNumbers[1]); } if (isset($allNumbers[2])) { $str[$allNumbers[2]]['letter'] = $letter; $str[$allNumbers[2]]['string'] = '='; // $str[] = '=:' . str_repeat($letter, $allNumbers[2]); } } var_export($str); $res = ''; foreach ($str as $num => $data) { $res .= '/' . $data['string'] . ':' . str_repeat($data['letter'], $num); } return $res; } echo mix("looping is fun but dangerous", "less dangerous than coding");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vTjLB
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   INIT_FCALL                                               'mix'
          1        SEND_VAL                                                 'looping+is+fun+but+dangerous'
          2        SEND_VAL                                                 'less+dangerous+than+coding'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5      > 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/vTjLB
function name:  prepareArray
number of ops:  48
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                                               'arsort'
         44        SEND_REF                                                 !4
         45        DO_ICALL                                                 
   20    46      > RETURN                                                   !4
   21    47*     > 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/vTjLB
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_assoc'
          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/vTjLB
function name:  compareArrays
number of ops:  41
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      
   35     2        ASSIGN                                                   !2, <array>
   36     3      > FE_RESET_R                                       $6      !0, ->20
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->20
          5    >   ASSIGN                                                   !4, ~7
   37     6        FETCH_DIM_W                                      $9      !2, !4
          7        ASSIGN_DIM                                               $9, 0
          8        OP_DATA                                                  !3
   38     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
   39    16    >   FETCH_DIM_W                                      $15     !2, !4
         17        ASSIGN_DIM                                               $15, 0
         18        OP_DATA                                                  !3
   36    19    > > JMP                                                      ->4
         20    >   FE_FREE                                                  $6
   43    21      > FE_RESET_R                                       $17     !1, ->38
         22    > > FE_FETCH_R                                       ~18     $17, !3, ->38
         23    >   ASSIGN                                                   !4, ~18
   44    24        FETCH_DIM_W                                      $20     !2, !4
         25        ASSIGN_DIM                                               $20, 1
         26        OP_DATA                                                  !3
   45    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
   46    34    >   FETCH_DIM_W                                      $26     !2, !4
         35        ASSIGN_DIM                                               $26, 1
         36        OP_DATA                                                  !3
   43    37    > > JMP                                                      ->22
         38    >   FE_FREE                                                  $17
   50    39      > RETURN                                                   !2
   51    40*     > RETURN                                                   null

End of function comparearrays

Function mix:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 107
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 107
Branch analysis from position: 45
2 jumps found. (Code = 46) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
2 jumps found. (Code = 46) Position 1 = 51, Position 2 = 55
Branch analysis from position: 51
2 jumps found. (Code = 47) Position 1 = 56, Position 2 = 62
Branch analysis from position: 56
2 jumps found. (Code = 46) Position 1 = 58, Position 2 = 61
Branch analysis from position: 58
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 71
Branch analysis from position: 63
2 jumps found. (Code = 46) Position 1 = 73, Position 2 = 75
Branch analysis from position: 73
2 jumps found. (Code = 46) Position 1 = 76, Position 2 = 80
Branch analysis from position: 76
2 jumps found. (Code = 47) Position 1 = 81, Position 2 = 87
Branch analysis from position: 81
2 jumps found. (Code = 46) Position 1 = 83, Position 2 = 86
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 96
Branch analysis from position: 88
2 jumps found. (Code = 43) Position 1 = 98, Position 2 = 106
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 106
Branch analysis from position: 96
Branch analysis from position: 86
Branch analysis from position: 87
Branch analysis from position: 80
Branch analysis from position: 75
Branch analysis from position: 71
Branch analysis from position: 61
Branch analysis from position: 62
Branch analysis from position: 55
Branch analysis from position: 50
Branch analysis from position: 107
2 jumps found. (Code = 77) Position 1 = 113, Position 2 = 126
Branch analysis from position: 113
2 jumps found. (Code = 78) Position 1 = 114, Position 2 = 126
Branch analysis from position: 114
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
Branch analysis from position: 126
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 126
Branch analysis from position: 107
Branch analysis from position: 35
filename:       /in/vTjLB
function name:  mix
number of ops:  129
compiled vars:  !0 = $s1, !1 = $s2, !2 = $s1Prepared, !3 = $s2Prepared, !4 = $intersectArray, !5 = $diffArray, !6 = $number, !7 = $letter, !8 = $resultArray, !9 = $str, !10 = $allNumbers, !11 = $res, !12 = $data, !13 = $num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   54     2        INIT_FCALL                                               'preparearray'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $14     
          5        ASSIGN                                                   !2, $14
   55     6        INIT_FCALL                                               'preparearray'
          7        SEND_VAR                                                 !1
          8        DO_FCALL                                      0  $16     
          9        ASSIGN                                                   !3, $16
   62    10        INIT_FCALL                                               'getintersect'
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !3
         13        DO_FCALL                                      0  $18     
         14        ASSIGN                                                   !4, $18
   67    15        INIT_FCALL                                               'comparearrays'
         16        INIT_FCALL                                               'array_diff_key'
         17        SEND_VAR                                                 !2
         18        SEND_VAR                                                 !4
         19        DO_ICALL                                         $20     
         20        SEND_VAR                                                 $20
         21        INIT_FCALL                                               'array_diff_key'
         22        SEND_VAR                                                 !3
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $21     
         25        SEND_VAR                                                 $21
         26        DO_FCALL                                      0  $22     
         27        ASSIGN                                                   !5, $22
   72    28      > FE_RESET_R                                       $24     !4, ->35
         29    > > FE_FETCH_R                                       ~25     $24, !6, ->35
         30    >   ASSIGN                                                   !7, ~25
   73    31        FETCH_DIM_W                                      $27     !8, !7
         32        ASSIGN_DIM                                               $27, 2
         33        OP_DATA                                                  !6
   72    34      > JMP                                                      ->29
         35    >   FE_FREE                                                  $24
   76    36        ADD                                              ~29     !5, !8
         37        ASSIGN                                                   !8, ~29
   78    38        INIT_FCALL                                               'var_export'
         39        SEND_VAR                                                 !8
         40        DO_ICALL                                                 
   79    41        ECHO                                                     '%0A'
   81    42        ASSIGN                                                   !9, <array>
   83    43      > FE_RESET_R                                       $33     !8, ->107
         44    > > FE_FETCH_R                                       ~34     $33, !10, ->107
         45    >   ASSIGN                                                   !7, ~34
   84    46        ISSET_ISEMPTY_DIM_OBJ                         0  ~36     !10, 0
         47      > JMPZ_EX                                          ~36     ~36, ->50
         48    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~37     !10, 1
         49        BOOL                                             ~36     ~37
         50    > > JMPZ_EX                                          ~36     ~36, ->55
         51    >   FETCH_DIM_R                                      ~38     !10, 0
         52        FETCH_DIM_R                                      ~39     !10, 1
         53        IS_SMALLER                                       ~40     ~39, ~38
         54        BOOL                                             ~36     ~40
         55    > > JMPNZ_EX                                         ~36     ~36, ->62
   85    56    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~41     !10, 0
         57      > JMPZ_EX                                          ~41     ~41, ->61
         58    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~42     !10, 1
         59        BOOL_NOT                                         ~43     ~42
         60        BOOL                                             ~41     ~43
         61    >   BOOL                                             ~36     ~41
         62    > > JMPZ                                                     ~36, ->71
   87    63    >   FETCH_DIM_R                                      ~44     !10, 0
         64        FETCH_DIM_W                                      $45     !9, ~44
         65        ASSIGN_DIM                                               $45, 'letter'
         66        OP_DATA                                                  !7
   88    67        FETCH_DIM_R                                      ~47     !10, 0
         68        FETCH_DIM_W                                      $48     !9, ~47
         69        ASSIGN_DIM                                               $48, 'string'
         70        OP_DATA                                                  '1'
   92    71    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~50     !10, 0
         72      > JMPZ_EX                                          ~50     ~50, ->75
         73    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~51     !10, 1
         74        BOOL                                             ~50     ~51
         75    > > JMPZ_EX                                          ~50     ~50, ->80
         76    >   FETCH_DIM_R                                      ~52     !10, 0
         77        FETCH_DIM_R                                      ~53     !10, 1
         78        IS_SMALLER                                       ~54     ~52, ~53
         79        BOOL                                             ~50     ~54
         80    > > JMPNZ_EX                                         ~50     ~50, ->87
   93    81    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~55     !10, 1
         82      > JMPZ_EX                                          ~55     ~55, ->86
         83    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~56     !10, 0
         84        BOOL_NOT                                         ~57     ~56
         85        BOOL                                             ~55     ~57
         86    >   BOOL                                             ~50     ~55
         87    > > JMPZ                                                     ~50, ->96
   95    88    >   FETCH_DIM_R                                      ~58     !10, 1
         89        FETCH_DIM_W                                      $59     !9, ~58
         90        ASSIGN_DIM                                               $59, 'letter'
         91        OP_DATA                                                  !7
   96    92        FETCH_DIM_R                                      ~61     !10, 1
         93        FETCH_DIM_W                                      $62     !9, ~61
         94        ASSIGN_DIM                                               $62, 'string'
         95        OP_DATA                                                  '2'
  100    96    >   ISSET_ISEMPTY_DIM_OBJ                         0          !10, 2
         97      > JMPZ                                                     ~64, ->106
  101    98    >   FETCH_DIM_R                                      ~65     !10, 2
         99        FETCH_DIM_W                                      $66     !9, ~65
        100        ASSIGN_DIM                                               $66, 'letter'
        101        OP_DATA                                                  !7
  102   102        FETCH_DIM_R                                      ~68     !10, 2
        103        FETCH_DIM_W                                      $69     !9, ~68
        104        ASSIGN_DIM                                               $69, 'string'
        105        OP_DATA                                                  '%3D'
   83   106    > > JMP                                                      ->44
        107    >   FE_FREE                                                  $33
  106   108        INIT_FCALL                                               'var_export'
        109        SEND_VAR                                                 !9
        110        DO_ICALL                                                 
  107   111        ASSIGN                                                   !11, ''
  108   112      > FE_RESET_R                                       $73     !9, ->126
        113    > > FE_FETCH_R                                       ~74     $73, !12, ->126
        114    >   ASSIGN                                                   !13, ~74
  109   115        FETCH_DIM_R                                      ~76     !12, 'string'
        116        CONCAT                                           ~77     '%2F', ~76
        117        CONCAT                                           ~78     ~77, '%3A'
        118        INIT_FCALL                                               'str_repeat'
        119        FETCH_DIM_R                                      ~79     !12, 'letter'
        120        SEND_VAL                                                 ~79
        121        SEND_VAR                                                 !13
        122        DO_ICALL                                         $80     
        123        CONCAT                                           ~81     ~78, $80
        124        ASSIGN_OP                                     8          !11, ~81
  108   125      > JMP                                                      ->113
        126    >   FE_FREE                                                  $73
  111   127      > RETURN                                                   !11
  112   128*     > RETURN                                                   null

End of function mix

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.31 ms | 1423 KiB | 40 Q