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) { if($key % 2 === 0) { $tempArr[$key] = bubbleSortAsc($value); } else { $tempArr[$key] = bubbleSortDesc($value); } } var_dump($tempArr); echo PHP_EOL; for($i = 0; $i < $colCount; $i++) { $columnArr[$i] = bubbleSort(array_column($tempArr, $i)); } var_dump($columnArr); echo PHP_EOL; for($i = 0; $i < $rowCount; $i++) { $tempArr[$i] = bubbleSort(array_column($columnArr, $i)); } $arr = $tempArr; } function bubbleSortAsc(array $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; } function bubbleSortDesc(array $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; } function bSort($arr) { bubbleSortRowCol($arr); return $arr; } bSort($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QYlFg
function name:  (null)
number of ops:  5
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   79     1        INIT_FCALL                                               'bsort'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   1

Function bubblesortrowcol:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 26
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 26
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 33
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 51
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 51
Branch analysis from position: 63
Branch analysis from position: 51
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 33
Branch analysis from position: 45
Branch analysis from position: 33
Branch analysis from position: 26
filename:       /in/QYlFg
function name:  bubbleSortRowCol
number of ops:  65
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, ->26
          9    > > FE_FETCH_R                                       ~16     $15, !5, ->26
         10    >   ASSIGN                                                   !6, ~16
   16    11        MOD                                              ~18     !6, 2
         12        IS_IDENTICAL                                             ~18, 0
         13      > JMPZ                                                     ~19, ->20
   17    14    >   INIT_FCALL_BY_NAME                                       'bubbleSortAsc'
         15        SEND_VAR_EX                                              !5
         16        DO_FCALL                                      0  $21     
         17        ASSIGN_DIM                                               !3, !6
         18        OP_DATA                                                  $21
         19      > JMP                                                      ->25
   19    20    >   INIT_FCALL_BY_NAME                                       'bubbleSortDesc'
         21        SEND_VAR_EX                                              !5
         22        DO_FCALL                                      0  $23     
         23        ASSIGN_DIM                                               !3, !6
         24        OP_DATA                                                  $23
   15    25    > > JMP                                                      ->9
         26    >   FE_FREE                                                  $15
   23    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                                 
         30        ECHO                                                     '%0A'
   25    31        ASSIGN                                                   !7, 0
         32      > JMP                                                      ->43
   26    33    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         34        INIT_FCALL                                               'array_column'
         35        SEND_VAR                                                 !3
         36        SEND_VAR                                                 !7
         37        DO_ICALL                                         $27     
         38        SEND_VAR_NO_REF_EX                                       $27
         39        DO_FCALL                                      0  $28     
         40        ASSIGN_DIM                                               !4, !7
         41        OP_DATA                                                  $28
   25    42        PRE_INC                                                  !7
         43    >   IS_SMALLER                                               !7, !1
         44      > JMPNZ                                                    ~30, ->33
   29    45    >   INIT_FCALL                                               'var_dump'
         46        SEND_VAR                                                 !4
         47        DO_ICALL                                                 
         48        ECHO                                                     '%0A'
   31    49        ASSIGN                                                   !7, 0
         50      > JMP                                                      ->61
   32    51    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         52        INIT_FCALL                                               'array_column'
         53        SEND_VAR                                                 !4
         54        SEND_VAR                                                 !7
         55        DO_ICALL                                         $34     
         56        SEND_VAR_NO_REF_EX                                       $34
         57        DO_FCALL                                      0  $35     
         58        ASSIGN_DIM                                               !3, !7
         59        OP_DATA                                                  $35
   31    60        PRE_INC                                                  !7
         61    >   IS_SMALLER                                               !7, !2
         62      > JMPNZ                                                    ~37, ->51
   35    63    >   ASSIGN                                                   !0, !3
   36    64      > RETURN                                                   null

End of function bubblesortrowcol

Function bubblesortasc:
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/QYlFg
function name:  bubbleSortAsc
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
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        ASSIGN                                                   !1, <false>
   40     2      > JMP                                                      ->24
   41     3    >   ASSIGN                                                   !1, <true>
   42     4        ASSIGN                                                   !2, 0
          5      > JMP                                                      ->20
   43     6    >   FETCH_DIM_R                                      ~8      !0, !2
          7        ASSIGN                                                   !3, ~8
   44     8        ADD                                              ~10     !2, 1
          9        FETCH_DIM_R                                      ~11     !0, ~10
         10        ASSIGN                                                   !4, ~11
   45    11        IS_SMALLER                                               !4, !3
         12      > JMPZ                                                     ~13, ->19
   46    13    >   ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  !4
   47    15        ADD                                              ~15     !2, 1
         16        ASSIGN_DIM                                               !0, ~15
         17        OP_DATA                                                  !3
   48    18        ASSIGN                                                   !1, <false>
   42    19    >   PRE_INC                                                  !2
         20    >   COUNT                                            ~19     !0
         21        SUB                                              ~20     ~19, 1
         22        IS_SMALLER                                               !2, ~20
         23      > JMPNZ                                                    ~21, ->6
   40    24    >   TYPE_CHECK                                    4          !1
         25      > JMPNZ                                                    ~22, ->3
   52    26    > > RETURN                                                   !0
   53    27*     > RETURN                                                   null

End of function bubblesortasc

Function bubblesortdesc:
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/QYlFg
function name:  bubbleSortDesc
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
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
   56     1        ASSIGN                                                   !1, <false>
   57     2      > JMP                                                      ->24
   58     3    >   ASSIGN                                                   !1, <true>
   59     4        ASSIGN                                                   !2, 0
          5      > JMP                                                      ->20
   60     6    >   FETCH_DIM_R                                      ~8      !0, !2
          7        ASSIGN                                                   !3, ~8
   61     8        ADD                                              ~10     !2, 1
          9        FETCH_DIM_R                                      ~11     !0, ~10
         10        ASSIGN                                                   !4, ~11
   62    11        IS_SMALLER                                               !3, !4
         12      > JMPZ                                                     ~13, ->19
   63    13    >   ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  !4
   64    15        ADD                                              ~15     !2, 1
         16        ASSIGN_DIM                                               !0, ~15
         17        OP_DATA                                                  !3
   65    18        ASSIGN                                                   !1, <false>
   59    19    >   PRE_INC                                                  !2
         20    >   COUNT                                            ~19     !0
         21        SUB                                              ~20     ~19, 1
         22        IS_SMALLER                                               !2, ~20
         23      > JMPNZ                                                    ~21, ->6
   57    24    >   TYPE_CHECK                                    4          !1
         25      > JMPNZ                                                    ~22, ->3
   69    26    > > RETURN                                                   !0
   70    27*     > RETURN                                                   null

End of function bubblesortdesc

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

End of function bsort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.56 ms | 1415 KiB | 19 Q