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); $tmp = $arr[$j]; $arr[$j] = $arr[$j+1]; $arr[$j+1] = $tmp; } } } 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); $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/XeaUb
function name:  (null)
number of ops:  14
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   27     1        ECHO                                                     'Before+sorting'
   28     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   30     5        INIT_FCALL                                               'bubble_sort'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $3      
          8        ASSIGN                                                   !0, $3
   31     9        ECHO                                                     'After+sorting+by+using+bubble+sort'
   32    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

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

End of function swap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.27 ms | 1406 KiB | 17 Q