3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = " i love you/i love her/you love me/you love me "; $sentence = explode('/',trim($x)); $value_counts = array_count_values($sentence); $expected_result = []; foreach($value_counts as $k=>$v){ if($v<2){ $expected_result[] = str_replace(' ','-',$k); }else{ $expected_result[] = str_replace(' ','-',$k); for($i=2;$i<=$v;$i++){ $expected_result[] = str_replace(' ','--',$k); } } } echo " ".implode('/', $expected_result)." ";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 47
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 47
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 27
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
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 = 36
Branch analysis from position: 46
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 36
Branch analysis from position: 46
Branch analysis from position: 36
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/Hh6Pj
function name:  (null)
number of ops:  56
compiled vars:  !0 = $x, !1 = $sentence, !2 = $value_counts, !3 = $expected_result, !4 = $v, !5 = $k, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '+i+love+you%2Fi+love+her%2Fyou+love+me%2Fyou+love+me+'
    3     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2F'
          3        INIT_FCALL                                               'trim'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $8      
          6        SEND_VAR                                                 $8
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !1, $9
    5     9        INIT_FCALL                                               'array_count_values'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !2, $11
    6    13        ASSIGN                                                   !3, <array>
    7    14      > FE_RESET_R                                       $14     !2, ->47
         15    > > FE_FETCH_R                                       ~15     $14, !4, ->47
         16    >   ASSIGN                                                   !5, ~15
    8    17        IS_SMALLER                                               !4, 2
         18      > JMPZ                                                     ~17, ->27
    9    19    >   INIT_FCALL                                               'str_replace'
         20        SEND_VAL                                                 '+'
         21        SEND_VAL                                                 '-'
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $19     
         24        ASSIGN_DIM                                               !3
         25        OP_DATA                                                  $19
         26      > JMP                                                      ->46
   11    27    >   INIT_FCALL                                               'str_replace'
         28        SEND_VAL                                                 '+'
         29        SEND_VAL                                                 '-'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                         $21     
         32        ASSIGN_DIM                                               !3
         33        OP_DATA                                                  $21
   12    34        ASSIGN                                                   !6, 2
         35      > JMP                                                      ->44
   13    36    >   INIT_FCALL                                               'str_replace'
         37        SEND_VAL                                                 '+'
         38        SEND_VAL                                                 '--'
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                         $24     
         41        ASSIGN_DIM                                               !3
         42        OP_DATA                                                  $24
   12    43        PRE_INC                                                  !6
         44    >   IS_SMALLER_OR_EQUAL                                      !6, !4
         45      > JMPNZ                                                    ~26, ->36
    7    46    > > JMP                                                      ->15
         47    >   FE_FREE                                                  $14
   18    48        INIT_FCALL                                               'implode'
         49        SEND_VAL                                                 '%2F'
         50        SEND_VAR                                                 !3
         51        DO_ICALL                                         $27     
         52        CONCAT                                           ~28     '+', $27
         53        CONCAT                                           ~29     ~28, '+'
         54        ECHO                                                     ~29
         55      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.66 ms | 1405 KiB | 23 Q