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 = []; foreach($arr as $key => $value) { $tempArr[$key] = bubbleSort($value); } for($i = 0; $i < $colCount; $i++) { $columnArr[$i] = bubbleSort(array_column($tempArr, $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/87vXM
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
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 34
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 47, Position 2 = 34
Branch analysis from position: 47
Branch analysis from position: 34
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 20
Branch analysis from position: 32
Branch analysis from position: 20
Branch analysis from position: 17
filename:       /in/87vXM
function name:  bubbleSortRowCol
number of ops:  49
compiled vars:  !0 = $arr, !1 = $colCount, !2 = $rowCount, !3 = $tempArr, !4 = $columnArr, !5 = $value, !6 = $key, !7 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        FETCH_DIM_R                                      ~8      !0, 0
          2        COUNT                                            ~9      ~8
          3        ASSIGN                                                   !1, ~9
   11     4        COUNT                                            ~11     !0
          5        ASSIGN                                                   !2, ~11
   12     6        ASSIGN                                                   !3, <array>
   13     7        ASSIGN                                                   !4, <array>
   15     8      > FE_RESET_R                                       $15     !0, ->17
          9    > > FE_FETCH_R                                       ~16     $15, !5, ->17
         10    >   ASSIGN                                                   !6, ~16
   16    11        INIT_FCALL_BY_NAME                                       'bubbleSort'
         12        SEND_VAR_EX                                              !5
         13        DO_FCALL                                      0  $19     
         14        ASSIGN_DIM                                               !3, !6
         15        OP_DATA                                                  $19
   15    16      > JMP                                                      ->9
         17    >   FE_FREE                                                  $15
   19    18        ASSIGN                                                   !7, 0
         19      > JMP                                                      ->30
   20    20    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         21        INIT_FCALL                                               'array_column'
         22        SEND_VAR                                                 !3
         23        SEND_VAR                                                 !7
         24        DO_ICALL                                         $22     
         25        SEND_VAR_NO_REF_EX                                       $22
         26        DO_FCALL                                      0  $23     
         27        ASSIGN_DIM                                               !4, !7
         28        OP_DATA                                                  $23
   19    29        PRE_INC                                                  !7
         30    >   IS_SMALLER                                               !7, !1
         31      > JMPNZ                                                    ~25, ->20
   23    32    >   ASSIGN                                                   !7, 0
         33      > JMP                                                      ->45
   24    34    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         35        INIT_FCALL                                               'array_column'
         36        FETCH_R                      local               ~28     !4
         37        SEND_VAL                                                 ~28
         38        SEND_VAR                                                 !7
         39        DO_ICALL                                         $29     
         40        SEND_VAR_NO_REF_EX                                       $29
         41        DO_FCALL                                      0  $30     
         42        ASSIGN_DIM                                               !3, !7
         43        OP_DATA                                                  $30
   23    44        PRE_INC                                                  !7
         45    >   IS_SMALLER                                               !7, !2
         46      > JMPNZ                                                    ~32, ->34
   27    47    >   ASSIGN                                                   !0, !3
   28    48      > 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/87vXM
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/87vXM
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:
166.28 ms | 1407 KiB | 19 Q