3v4l.org

run code in 300+ PHP versions simultaneously
<?php function bubble_sort($arr) { $size = count($arr); for ($i=0; $i<$size; $i++) { for ($j=0; $j<$size-1-$i; $j++) { if ($arr[$j+1] < $arr[$j]) { swap($arr, $j, $j+1); } } } return $arr; } function swap(&$arr, $a, $b) { $tmp = $arr[$a]; $arr[$a] = $arr[$b]; $arr[$b] = $tmp; } /* test bubble sort */ $arr = array(1,3,2,8,5,7,4,0); print("Before sorting"); print_r($arr); bubble_sort($arr); print("After sorting by using bubble sort"); print_r($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aG57t
function name:  (null)
number of ops:  13
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   24     1        ECHO                                                     'Before+sorting'
   25     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   27     5        INIT_FCALL                                               'bubble_sort'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0          
   28     8        ECHO                                                     'After+sorting+by+using+bubble+sort'
   29     9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function bubble_sort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 5
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 7
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 5
Branch analysis from position: 26
Branch analysis from position: 5
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 7
Branch analysis from position: 23
Branch analysis from position: 7
Branch analysis from position: 18
filename:       /in/aG57t
function name:  bubble_sort
number of ops:  28
compiled vars:  !0 = $arr, !1 = $size, !2 = $i, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        COUNT                                            ~4      !0
          2        ASSIGN                                                   !1, ~4
    4     3        ASSIGN                                                   !2, 0
          4      > JMP                                                      ->24
    5     5    >   ASSIGN                                                   !3, 0
          6      > JMP                                                      ->19
    6     7    >   ADD                                              ~8      !3, 1
          8        FETCH_DIM_R                                      ~9      !0, ~8
          9        FETCH_DIM_R                                      ~10     !0, !3
         10        IS_SMALLER                                               ~9, ~10
         11      > JMPZ                                                     ~11, ->18
    7    12    >   INIT_FCALL_BY_NAME                                       'swap'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAR_EX                                              !3
         15        ADD                                              ~12     !3, 1
         16        SEND_VAL_EX                                              ~12
         17        DO_FCALL                                      0          
    5    18    >   PRE_INC                                                  !3
         19    >   SUB                                              ~15     !1, 1
         20        SUB                                              ~16     ~15, !2
         21        IS_SMALLER                                               !3, ~16
         22      > JMPNZ                                                    ~17, ->7
    4    23    >   PRE_INC                                                  !2
         24    >   IS_SMALLER                                               !2, !1
         25      > JMPNZ                                                    ~19, ->5
   11    26    > > RETURN                                                   !0
   12    27*     > RETURN                                                   null

End of function bubble_sort

Function swap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aG57t
function name:  swap
number of ops:  11
compiled vars:  !0 = $arr, !1 = $a, !2 = $b, !3 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   15     3        FETCH_DIM_R                                      ~4      !0, !1
          4        ASSIGN                                                   !3, ~4
   16     5        FETCH_DIM_R                                      ~7      !0, !2
          6        ASSIGN_DIM                                               !0, !1
          7        OP_DATA                                                  ~7
   17     8        ASSIGN_DIM                                               !0, !2
          9        OP_DATA                                                  !3
   18    10      > RETURN                                                   null

End of function swap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.12 ms | 1403 KiB | 16 Q