3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array(1,2,1,3,2,1,3,2,1,3,2,1,2,3,1,2,3); echo implode(" ", $a) . "\n"; $useSort = true; if ($useSort) { sort($a); } else { $first = 0; $last = sizeof($a) - 1; echo $last; for($i = $first; $i <= $last;) { echo $i . "\n"; $v = $a[$i]; echo "Found $v at index $i\n"; if ($v == 1) { echo "$v is low, swapping with value in index $first\n"; swap($a, $i, $first); $first += 1; } if ($v == 3) { echo "$v is high, swapping with value in index $last\n"; swap($a, $i, $last); $last -= 1; continue; } $i += 1; } } echo implode(" ", $a) . "\n"; function swap(&$arr, $k1, $k2) { echo "Swapping $k1 and $k2\n"; $tmp = $arr[$k2]; $arr[$k2] = $arr[$k1]; $arr[$k1] = $tmp; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 20
Branch analysis from position: 60
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 43
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 57
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 20
Branch analysis from position: 60
Branch analysis from position: 20
Branch analysis from position: 43
filename:       /in/DId3B
function name:  (null)
number of ops:  67
compiled vars:  !0 = $a, !1 = $useSort, !2 = $first, !3 = $last, !4 = $i, !5 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        CONCAT                                           ~8      $7, '%0A'
          6        ECHO                                                     ~8
    5     7        ASSIGN                                                   !1, <true>
    7     8      > JMPZ                                                     !1, ->13
    8     9    >   INIT_FCALL                                               'sort'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
         12      > JMP                                                      ->60
   11    13    >   ASSIGN                                                   !2, 0
   12    14        COUNT                                            ~12     !0
         15        SUB                                              ~13     ~12, 1
         16        ASSIGN                                                   !3, ~13
   13    17        ECHO                                                     !3
   15    18        ASSIGN                                                   !4, !2
         19      > JMP                                                      ->58
   17    20    >   CONCAT                                           ~16     !4, '%0A'
         21        ECHO                                                     ~16
   18    22        FETCH_DIM_R                                      ~17     !0, !4
         23        ASSIGN                                                   !5, ~17
   19    24        ROPE_INIT                                     5  ~20     'Found+'
         25        ROPE_ADD                                      1  ~20     ~20, !5
         26        ROPE_ADD                                      2  ~20     ~20, '+at+index+'
         27        ROPE_ADD                                      3  ~20     ~20, !4
         28        ROPE_END                                      4  ~19     ~20, '%0A'
         29        ECHO                                                     ~19
   21    30        IS_EQUAL                                                 !5, 1
         31      > JMPZ                                                     ~23, ->43
   22    32    >   ROPE_INIT                                     4  ~25     !5
         33        ROPE_ADD                                      1  ~25     ~25, '+is+low%2C+swapping+with+value+in+index+'
         34        ROPE_ADD                                      2  ~25     ~25, !2
         35        ROPE_END                                      3  ~24     ~25, '%0A'
         36        ECHO                                                     ~24
   23    37        INIT_FCALL_BY_NAME                                       'swap'
         38        SEND_VAR_EX                                              !0
         39        SEND_VAR_EX                                              !4
         40        SEND_VAR_EX                                              !2
         41        DO_FCALL                                      0          
   24    42        ASSIGN_OP                                     1          !2, 1
   26    43    >   IS_EQUAL                                                 !5, 3
         44      > JMPZ                                                     ~29, ->57
   27    45    >   ROPE_INIT                                     4  ~31     !5
         46        ROPE_ADD                                      1  ~31     ~31, '+is+high%2C+swapping+with+value+in+index+'
         47        ROPE_ADD                                      2  ~31     ~31, !3
         48        ROPE_END                                      3  ~30     ~31, '%0A'
         49        ECHO                                                     ~30
   28    50        INIT_FCALL_BY_NAME                                       'swap'
         51        SEND_VAR_EX                                              !0
         52        SEND_VAR_EX                                              !4
         53        SEND_VAR_EX                                              !3
         54        DO_FCALL                                      0          
   29    55        ASSIGN_OP                                     2          !3, 1
   30    56      > JMP                                                      ->58
   32    57    >   ASSIGN_OP                                     1          !4, 1
   15    58    >   IS_SMALLER_OR_EQUAL                                      !4, !3
         59      > JMPNZ                                                    ~36, ->20
   36    60    >   INIT_FCALL                                               'implode'
         61        SEND_VAL                                                 '+'
         62        SEND_VAR                                                 !0
         63        DO_ICALL                                         $37     
         64        CONCAT                                           ~38     $37, '%0A'
         65        ECHO                                                     ~38
   44    66      > RETURN                                                   1

Function swap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DId3B
function name:  swap
number of ops:  17
compiled vars:  !0 = $arr, !1 = $k1, !2 = $k2, !3 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   40     3        ROPE_INIT                                     5  ~5      'Swapping+'
          4        ROPE_ADD                                      1  ~5      ~5, !1
          5        ROPE_ADD                                      2  ~5      ~5, '+and+'
          6        ROPE_ADD                                      3  ~5      ~5, !2
          7        ROPE_END                                      4  ~4      ~5, '%0A'
          8        ECHO                                                     ~4
   41     9        FETCH_DIM_R                                      ~8      !0, !2
         10        ASSIGN                                                   !3, ~8
   42    11        FETCH_DIM_R                                      ~11     !0, !1
         12        ASSIGN_DIM                                               !0, !2
         13        OP_DATA                                                  ~11
   43    14        ASSIGN_DIM                                               !0, !1
         15        OP_DATA                                                  !3
   44    16      > RETURN                                                   null

End of function swap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.35 ms | 1404 KiB | 17 Q