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); } } 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 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; } print_r(bSort($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/59aTg
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>
   76     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 = 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 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 29
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 43
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 43
Branch analysis from position: 55
Branch analysis from position: 43
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 29
Branch analysis from position: 41
Branch analysis from position: 29
Branch analysis from position: 26
filename:       /in/59aTg
function name:  bubbleSortRowCol
number of ops:  57
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
   24    27        ASSIGN                                                   !7, 0
         28      > JMP                                                      ->39
   25    29    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         30        INIT_FCALL                                               'array_column'
         31        SEND_VAR                                                 !3
         32        SEND_VAR                                                 !7
         33        DO_ICALL                                         $26     
         34        SEND_VAR_NO_REF_EX                                       $26
         35        DO_FCALL                                      0  $27     
         36        ASSIGN_DIM                                               !4, !7
         37        OP_DATA                                                  $27
   24    38        PRE_INC                                                  !7
         39    >   IS_SMALLER                                               !7, !1
         40      > JMPNZ                                                    ~29, ->29
   28    41    >   ASSIGN                                                   !7, 0
         42      > JMP                                                      ->53
   29    43    >   INIT_FCALL_BY_NAME                                       'bubbleSort'
         44        INIT_FCALL                                               'array_column'
         45        SEND_VAR                                                 !4
         46        SEND_VAR                                                 !7
         47        DO_ICALL                                         $32     
         48        SEND_VAR_NO_REF_EX                                       $32
         49        DO_FCALL                                      0  $33     
         50        ASSIGN_DIM                                               !3, !7
         51        OP_DATA                                                  $33
   28    52        PRE_INC                                                  !7
         53    >   IS_SMALLER                                               !7, !2
         54      > JMPNZ                                                    ~35, ->43
   32    55    >   ASSIGN                                                   !0, !3
   33    56      > 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/59aTg
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
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        ASSIGN                                                   !1, <false>
   37     2      > JMP                                                      ->24
   38     3    >   ASSIGN                                                   !1, <true>
   39     4        ASSIGN                                                   !2, 0
          5      > JMP                                                      ->20
   40     6    >   FETCH_DIM_R                                      ~8      !0, !2
          7        ASSIGN                                                   !3, ~8
   41     8        ADD                                              ~10     !2, 1
          9        FETCH_DIM_R                                      ~11     !0, ~10
         10        ASSIGN                                                   !4, ~11
   42    11        IS_SMALLER                                               !4, !3
         12      > JMPZ                                                     ~13, ->19
   43    13    >   ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  !4
   44    15        ADD                                              ~15     !2, 1
         16        ASSIGN_DIM                                               !0, ~15
         17        OP_DATA                                                  !3
   45    18        ASSIGN                                                   !1, <false>
   39    19    >   PRE_INC                                                  !2
         20    >   COUNT                                            ~19     !0
         21        SUB                                              ~20     ~19, 1
         22        IS_SMALLER                                               !2, ~20
         23      > JMPNZ                                                    ~21, ->6
   37    24    >   TYPE_CHECK                                    4          !1
         25      > JMPNZ                                                    ~22, ->3
   49    26    > > RETURN                                                   !0
   50    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/59aTg
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
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        ASSIGN                                                   !1, <false>
   54     2      > JMP                                                      ->24
   55     3    >   ASSIGN                                                   !1, <true>
   56     4        ASSIGN                                                   !2, 0
          5      > JMP                                                      ->20
   57     6    >   FETCH_DIM_R                                      ~8      !0, !2
          7        ASSIGN                                                   !3, ~8
   58     8        ADD                                              ~10     !2, 1
          9        FETCH_DIM_R                                      ~11     !0, ~10
         10        ASSIGN                                                   !4, ~11
   59    11        IS_SMALLER                                               !3, !4
         12      > JMPZ                                                     ~13, ->19
   60    13    >   ASSIGN_DIM                                               !0, !2
         14        OP_DATA                                                  !4
   61    15        ADD                                              ~15     !2, 1
         16        ASSIGN_DIM                                               !0, ~15
         17        OP_DATA                                                  !3
   62    18        ASSIGN                                                   !1, <false>
   56    19    >   PRE_INC                                                  !2
         20    >   COUNT                                            ~19     !0
         21        SUB                                              ~20     ~19, 1
         22        IS_SMALLER                                               !2, ~20
         23      > JMPNZ                                                    ~21, ->6
   54    24    >   TYPE_CHECK                                    4          !1
         25      > JMPNZ                                                    ~22, ->3
   66    26    > > RETURN                                                   !0
   67    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/59aTg
function name:  bSort
number of ops:  6
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        INIT_FCALL                                               'bubblesortrowcol'
          2        SEND_REF                                                 !0
          3        DO_FCALL                                      0          
   73     4      > RETURN                                                   !0
   74     5*     > RETURN                                                   null

End of function bsort

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.82 ms | 1415 KiB | 19 Q