3v4l.org

run code in 300+ PHP versions simultaneously
<?php function swap_words($words, $synonyms) { $all_synonyms = array_unique(array_merge(...$synonyms)); $result = []; $word = $words[0]; if (in_array($word, $all_synonyms)) { foreach ($synonyms[1] as $replacement) { $result[] = "$replacement " . implode(' ', array_slice($words, 1)); } foreach ($synonyms[2] as $replacement) { $result[] = implode(' ', array_slice($words, 1)) . " $replacement"; } } $c = count($words) - 1; $word = $words[$c]; if (in_array($word, $all_synonyms)) { foreach ($synonyms[1] as $replacement) { $result[] = "$replacement " . implode(' ', array_slice($words, 0, $c)); } foreach ($synonyms[2] as $replacement) { $result[] = implode(' ', array_slice($words, 0, $c)) . " $replacement"; } } return $result; } $words = ['no of', 'autumn', 'sales']; $tot = ['1'=>array('count','total','num of','no of', 'no. of'), '2'=>array('count')]; print_r(swap_words($words, $tot)); $words = ['autumn', 'sales', 'count']; print_r(swap_words($words, $tot));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/29pku
function name:  (null)
number of ops:  18
compiled vars:  !0 = $words, !1 = $tot
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, <array>
   31     1        ASSIGN                                                   !1, <array>
   33     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'swap_words'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   35     9        ASSIGN                                                   !0, <array>
   36    10        INIT_FCALL                                               'print_r'
         11        INIT_FCALL                                               'swap_words'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !1
         14        DO_FCALL                                      0  $7      
         15        SEND_VAR                                                 $7
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function swap_words:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 54
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 35
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 35
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 35
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 53
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 53
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 102
Branch analysis from position: 64
2 jumps found. (Code = 77) Position 1 = 66, Position 2 = 82
Branch analysis from position: 66
2 jumps found. (Code = 78) Position 1 = 67, Position 2 = 82
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
Branch analysis from position: 82
2 jumps found. (Code = 77) Position 1 = 85, Position 2 = 101
Branch analysis from position: 85
2 jumps found. (Code = 78) Position 1 = 86, Position 2 = 101
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
Branch analysis from position: 101
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 101
Branch analysis from position: 82
Branch analysis from position: 102
Branch analysis from position: 53
Branch analysis from position: 35
Branch analysis from position: 54
filename:       /in/29pku
function name:  swap_words
number of ops:  104
compiled vars:  !0 = $words, !1 = $synonyms, !2 = $all_synonyms, !3 = $result, !4 = $word, !5 = $replacement, !6 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        INIT_FCALL                                               'array_unique'
          3        INIT_FCALL                                               'array_merge'
          4        SEND_UNPACK                                              !1
          5        CHECK_UNDEF_ARGS                                         
          6        DO_ICALL                                         $7      
          7        SEND_VAR                                                 $7
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !2, $8
    5    10        ASSIGN                                                   !3, <array>
    6    11        FETCH_DIM_R                                      ~11     !0, 0
         12        ASSIGN                                                   !4, ~11
    7    13        INIT_FCALL                                               'in_array'
         14        SEND_VAR                                                 !4
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $13     
         17      > JMPZ                                                     $13, ->54
    8    18    >   FETCH_DIM_R                                      ~14     !1, 1
         19      > FE_RESET_R                                       $15     ~14, ->35
         20    > > FE_FETCH_R                                               $15, !5, ->35
    9    21    >   NOP                                                      
         22        FAST_CONCAT                                      ~17     !5, '+'
         23        INIT_FCALL                                               'implode'
         24        SEND_VAL                                                 '+'
         25        INIT_FCALL                                               'array_slice'
         26        SEND_VAR                                                 !0
         27        SEND_VAL                                                 1
         28        DO_ICALL                                         $18     
         29        SEND_VAR                                                 $18
         30        DO_ICALL                                         $19     
         31        CONCAT                                           ~20     ~17, $19
         32        ASSIGN_DIM                                               !3
         33        OP_DATA                                                  ~20
    8    34      > JMP                                                      ->20
         35    >   FE_FREE                                                  $15
   11    36        FETCH_DIM_R                                      ~21     !1, 2
         37      > FE_RESET_R                                       $22     ~21, ->53
         38    > > FE_FETCH_R                                               $22, !5, ->53
   12    39    >   INIT_FCALL                                               'implode'
         40        SEND_VAL                                                 '+'
         41        INIT_FCALL                                               'array_slice'
         42        SEND_VAR                                                 !0
         43        SEND_VAL                                                 1
         44        DO_ICALL                                         $24     
         45        SEND_VAR                                                 $24
         46        DO_ICALL                                         $25     
         47        NOP                                                      
         48        FAST_CONCAT                                      ~26     '+', !5
         49        CONCAT                                           ~27     $25, ~26
         50        ASSIGN_DIM                                               !3
         51        OP_DATA                                                  ~27
   11    52      > JMP                                                      ->38
         53    >   FE_FREE                                                  $22
   16    54    >   COUNT                                            ~28     !0
         55        SUB                                              ~29     ~28, 1
         56        ASSIGN                                                   !6, ~29
   17    57        FETCH_DIM_R                                      ~31     !0, !6
         58        ASSIGN                                                   !4, ~31
   18    59        INIT_FCALL                                               'in_array'
         60        SEND_VAR                                                 !4
         61        SEND_VAR                                                 !2
         62        DO_ICALL                                         $33     
         63      > JMPZ                                                     $33, ->102
   19    64    >   FETCH_DIM_R                                      ~34     !1, 1
         65      > FE_RESET_R                                       $35     ~34, ->82
         66    > > FE_FETCH_R                                               $35, !5, ->82
   20    67    >   NOP                                                      
         68        FAST_CONCAT                                      ~37     !5, '+'
         69        INIT_FCALL                                               'implode'
         70        SEND_VAL                                                 '+'
         71        INIT_FCALL                                               'array_slice'
         72        SEND_VAR                                                 !0
         73        SEND_VAL                                                 0
         74        SEND_VAR                                                 !6
         75        DO_ICALL                                         $38     
         76        SEND_VAR                                                 $38
         77        DO_ICALL                                         $39     
         78        CONCAT                                           ~40     ~37, $39
         79        ASSIGN_DIM                                               !3
         80        OP_DATA                                                  ~40
   19    81      > JMP                                                      ->66
         82    >   FE_FREE                                                  $35
   22    83        FETCH_DIM_R                                      ~41     !1, 2
         84      > FE_RESET_R                                       $42     ~41, ->101
         85    > > FE_FETCH_R                                               $42, !5, ->101
   23    86    >   INIT_FCALL                                               'implode'
         87        SEND_VAL                                                 '+'
         88        INIT_FCALL                                               'array_slice'
         89        SEND_VAR                                                 !0
         90        SEND_VAL                                                 0
         91        SEND_VAR                                                 !6
         92        DO_ICALL                                         $44     
         93        SEND_VAR                                                 $44
         94        DO_ICALL                                         $45     
         95        NOP                                                      
         96        FAST_CONCAT                                      ~46     '+', !5
         97        CONCAT                                           ~47     $45, ~46
         98        ASSIGN_DIM                                               !3
         99        OP_DATA                                                  ~47
   22   100      > JMP                                                      ->85
        101    >   FE_FREE                                                  $42
   27   102    > > RETURN                                                   !3
   28   103*     > RETURN                                                   null

End of function swap_words

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.33 ms | 1031 KiB | 21 Q