3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [15, 16, 8, 1], [2, 3, 4, 7], [9, 11, 19, 6] ]; global $sortedArr; function bubbleSortRowCol($arr) { $colCount = 0; $tempArr = []; $columnArr = []; foreach($arr as $key => $row) { $tempArr[$key] = bubbleSort($row); $colCount = count($row); } for($i = 0; $i < $colCount; $i++) { $columnArr[] = bubbleSort(array_column($arr, $i)); } if($columnArr !== $sortedArr) { bubbleSortRowCol($columnArr); } return $tempArr; } function fullSortArr($arr) { $fullArr = []; $tempArr = []; $countArr = []; $n = 0; foreach($arr as $value) { $fullArr = array_merge($fullArr, $value); $countArr[] = count($value); } asort($fullArr); foreach($countArr as $key => $length) { $tempArr[] = array_slice($fullArr, $n, $length); $n += $length; } return $tempArr; } function bubbleSort($arr) { $sorted = false; while (false === $sorted) { $sorted = true; for ($i = 0; $i < count($arr) - 1; $i++) { $current = $arr[$i]; $next = $arr[$i + 1]; if ($next < $current) { $arr[$i] = $next; $arr[$i + 1] = $current; $sorted = false; } } } return $arr; } $sortedArr = fullSortArr($arr); print_r(bubbleSortRowCol($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D1V0B
function name:  (null)
number of ops:  13
compiled vars:  !0 = $arr, !1 = $sortedArr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        BIND_GLOBAL                                              !1, 'sortedArr'
   74     2        INIT_FCALL                                               'fullsortarr'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   76     6        INIT_FCALL                                               'print_r'
          7        INIT_FCALL                                               'bubblesortrowcol'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $5      
         10        SEND_VAR                                                 $5
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

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

End of function bubblesortrowcol

Function fullsortarr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 32
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 32
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 16
filename:       /in/D1V0B
function name:  fullSortArr
number of ops:  35
compiled vars:  !0 = $arr, !1 = $fullArr, !2 = $tempArr, !3 = $countArr, !4 = $n, !5 = $value, !6 = $length, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   35     1        ASSIGN                                                   !1, <array>
   36     2        ASSIGN                                                   !2, <array>
   37     3        ASSIGN                                                   !3, <array>
   38     4        ASSIGN                                                   !4, 0
   40     5      > FE_RESET_R                                       $12     !0, ->16
          6    > > FE_FETCH_R                                               $12, !5, ->16
   41     7    >   INIT_FCALL                                               'array_merge'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !5
         10        DO_ICALL                                         $13     
         11        ASSIGN                                                   !1, $13
   43    12        COUNT                                            ~16     !5
         13        ASSIGN_DIM                                               !3
         14        OP_DATA                                                  ~16
   40    15      > JMP                                                      ->6
         16    >   FE_FREE                                                  $12
   46    17        INIT_FCALL                                               'asort'
         18        SEND_REF                                                 !1
         19        DO_ICALL                                                 
   48    20      > FE_RESET_R                                       $18     !3, ->32
         21    > > FE_FETCH_R                                       ~19     $18, !6, ->32
         22    >   ASSIGN                                                   !7, ~19
   49    23        INIT_FCALL                                               'array_slice'
         24        SEND_VAR                                                 !1
         25        SEND_VAR                                                 !4
         26        SEND_VAR                                                 !6
         27        DO_ICALL                                         $22     
         28        ASSIGN_DIM                                               !2
         29        OP_DATA                                                  $22
   51    30        ASSIGN_OP                                     1          !4, !6
   48    31      > JMP                                                      ->21
         32    >   FE_FREE                                                  $18
   54    33      > RETURN                                                   !2
   55    34*     > RETURN                                                   null

End of function fullsortarr

Function bubblesort:
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 = 3
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 6
Branch analysis from position: 24
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 6
Branch analysis from position: 24
Branch analysis from position: 6
Branch analysis from position: 19
filename:       /in/D1V0B
function name:  bubbleSort
number of ops:  28
compiled vars:  !0 = $arr, !1 = $sorted, !2 = $i, !3 = $current, !4 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   RECV                                             !0      
   58     1        ASSIGN                                                   !1, <false>
   59     2      > JMP                                                      ->24
   60     3    >   ASSIGN                                                   !1, <true>
   61     4        ASSIGN                                                   !2, 0
          5      > JMP                                                      ->20
   62     6    >   FETCH_DIM_R                                      ~8      !0, !2
          7        ASSIGN                                                   !3, ~8
   63     8        ADD                                              ~10     !2, 1
          9        FETCH_DIM_R                                      ~11     !0, ~10
         10        ASSIGN                                                   !4, ~11
   64    11        IS_SMALLER                                               !4, !3
         12      > JMPZ                                                     ~13, ->19
   65    13    >   ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  !4
   66    15        ADD                                              ~15     !2, 1
         16        ASSIGN_DIM                                               !0, ~15
         17        OP_DATA                                                  !3
   67    18        ASSIGN                                                   !1, <false>
   61    19    >   PRE_INC                                                  !2
         20    >   COUNT                                            ~19     !0
         21        SUB                                              ~20     ~19, 1
         22        IS_SMALLER                                               !2, ~20
         23      > JMPNZ                                                    ~21, ->6
   59    24    >   TYPE_CHECK                                    4          !1
         25      > JMPNZ                                                    ~22, ->3
   71    26    > > RETURN                                                   !0
   72    27*     > RETURN                                                   null

End of function bubblesort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.38 ms | 1411 KiB | 25 Q