3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [15, 16, 8, 1], [2, 3, 4, 7], [9, 11, 19, 6] ]; function bubbleSortRowCol(&$arr) { $colCount = count($arr[0]); $rowCount = count($arr); $tempArr = []; $columnArr = []; for($i = 0; $i < $colCount; $i++) { $columnArr[$i] = bubbleSort(array_column($arr, $i)); } for($i = 0; $i < $colCount; $i++) { $columnArr[$i] = bubbleSort(array_column($columnArr, $i)); } for($i = 0; $i < $rowCount; $i++) { $tempArr[$i] = bubbleSort(array_column($columnArr, $i)); } $arr = $tempArr; } function bubbleSort($arr) { $n = sizeof($arr); for ($i = 1; $i < $n; $i++) { $flag = false; for ($j = $n - 1; $j >= $i; $j--) { if($arr[$j-1] > $arr[$j]) { $tmp = $arr[$j - 1]; $arr[$j - 1] = $arr[$j]; $arr[$j] = $tmp; $flag = true; } } if (!$flag) { break; } } return $arr; } function bSort($arr) { bubbleSortRowCol($arr); return $arr; } print_r(bSort($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N6JLE
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   58     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'bsort'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function bubblesortrowcol:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 10
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 24
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 38
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 38
Branch analysis from position: 50
Branch analysis from position: 38
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 24
Branch analysis from position: 36
Branch analysis from position: 24
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 10
Branch analysis from position: 22
Branch analysis from position: 10
filename:       /in/N6JLE
function name:  bubbleSortRowCol
number of ops:  52
compiled vars:  !0 = $arr, !1 = $colCount, !2 = $rowCount, !3 = $tempArr, !4 = $columnArr, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FETCH_DIM_R                                      ~6      !0, 0
          2        COUNT                                            ~7      ~6
          3        ASSIGN                                                   !1, ~7
   11     4        COUNT                                            ~9      !0
          5        ASSIGN                                                   !2, ~9
   12     6        ASSIGN                                                   !3, <array>
   13     7        ASSIGN                                                   !4, <array>
   15     8        ASSIGN                                                   !5, 0
          9      > JMP                                                      ->20
   16    10    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         11        INIT_FCALL                                               'array_column'
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !5
         14        DO_ICALL                                         $15     
         15        SEND_VAR_NO_REF_EX                                       $15
         16        DO_FCALL                                      0  $16     
         17        ASSIGN_DIM                                               !4, !5
         18        OP_DATA                                                  $16
   15    19        PRE_INC                                                  !5
         20    >   IS_SMALLER                                               !5, !1
         21      > JMPNZ                                                    ~18, ->10
   19    22    >   ASSIGN                                                   !5, 0
         23      > JMP                                                      ->34
   20    24    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         25        INIT_FCALL                                               'array_column'
         26        SEND_VAR                                                 !4
         27        SEND_VAR                                                 !5
         28        DO_ICALL                                         $21     
         29        SEND_VAR_NO_REF_EX                                       $21
         30        DO_FCALL                                      0  $22     
         31        ASSIGN_DIM                                               !4, !5
         32        OP_DATA                                                  $22
   19    33        PRE_INC                                                  !5
         34    >   IS_SMALLER                                               !5, !1
         35      > JMPNZ                                                    ~24, ->24
   23    36    >   ASSIGN                                                   !5, 0
         37      > JMP                                                      ->48
   24    38    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         39        INIT_FCALL                                               'array_column'
         40        SEND_VAR                                                 !4
         41        SEND_VAR                                                 !5
         42        DO_ICALL                                         $27     
         43        SEND_VAR_NO_REF_EX                                       $27
         44        DO_FCALL                                      0  $28     
         45        ASSIGN_DIM                                               !3, !5
         46        OP_DATA                                                  $28
   23    47        PRE_INC                                                  !5
         48    >   IS_SMALLER                                               !5, !2
         49      > JMPNZ                                                    ~30, ->38
   27    50    >   ASSIGN                                                   !0, !3
   28    51      > RETURN                                                   null

End of function bubblesortrowcol

Function bubblesort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 5
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 9
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 5
Branch analysis from position: 33
Branch analysis from position: 5
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 9
Branch analysis from position: 27
Branch analysis from position: 9
Branch analysis from position: 24
filename:       /in/N6JLE
function name:  bubbleSort
number of ops:  35
compiled vars:  !0 = $arr, !1 = $n, !2 = $i, !3 = $flag, !4 = $j, !5 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   32     1        COUNT                                            ~6      !0
          2        ASSIGN                                                   !1, ~6
   33     3        ASSIGN                                                   !2, 1
          4      > JMP                                                      ->31
   34     5    >   ASSIGN                                                   !3, <false>
   35     6        SUB                                              ~10     !1, 1
          7        ASSIGN                                                   !4, ~10
          8      > JMP                                                      ->25
   36     9    >   SUB                                              ~12     !4, 1
         10        FETCH_DIM_R                                      ~13     !0, ~12
         11        FETCH_DIM_R                                      ~14     !0, !4
         12        IS_SMALLER                                               ~14, ~13
         13      > JMPZ                                                     ~15, ->24
   37    14    >   SUB                                              ~16     !4, 1
         15        FETCH_DIM_R                                      ~17     !0, ~16
         16        ASSIGN                                                   !5, ~17
   38    17        SUB                                              ~19     !4, 1
         18        FETCH_DIM_R                                      ~21     !0, !4
         19        ASSIGN_DIM                                               !0, ~19
         20        OP_DATA                                                  ~21
   39    21        ASSIGN_DIM                                               !0, !4
         22        OP_DATA                                                  !5
   40    23        ASSIGN                                                   !3, <true>
   35    24    >   PRE_DEC                                                  !4
         25    >   IS_SMALLER_OR_EQUAL                                      !2, !4
         26      > JMPNZ                                                    ~25, ->9
   43    27    >   BOOL_NOT                                         ~26     !3
         28      > JMPZ                                                     ~26, ->30
   44    29    > > JMP                                                      ->33
   33    30    >   PRE_INC                                                  !2
         31    >   IS_SMALLER                                               !2, !1
         32      > JMPNZ                                                    ~28, ->5
   48    33    > > RETURN                                                   !0
   49    34*     > RETURN                                                   null

End of function bubblesort

Function bsort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N6JLE
function name:  bSort
number of ops:  6
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   53     1        INIT_FCALL                                               'bubblesortrowcol'
          2        SEND_REF                                                 !0
          3        DO_FCALL                                      0          
   55     4      > RETURN                                                   !0
   56     5*     > RETURN                                                   null

End of function bsort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.08 ms | 952 KiB | 20 Q