3v4l.org

run code in 300+ PHP versions simultaneously
<?php $list = [1,2,3,3,44,5,6,2,3,2,33,8,8,6,"Kanyin",9,24,21,3,44,5,102,33,43,"Kanyin", "Kanyinsola", "Adeola", "adeola", "Adeolas", "Adeola1","Adeola"]; bubbleSort($list); function bubbleSort( array $lst ) { $numList = count( $lst ); $swapped = false; do{ $swapped = false; for( $i=0; $i < $numList - 1; $i++ ) { if( $lst[$i] > $lst[$i+1]){ $temp = $lst[$i]; $lst[$i] = $lst[$i+1]; $lst[$i+1] = $temp; $swapped = true; } } } while ( $swapped == true); echo ( implode(" ", $lst)); } selectionSort( $list ); function selectionSort( array $lst ) { $numList = count( $lst ); for( $i=0; $i < $numList; $i++ ) { $index = 0; $smallest = $lst[$i]; for( $j = $i; $j < $numList; $j++ ) { if( $lst[$j] < $smallest ) { $smallest = $lst[$j]; $index = $j; } $temp = $lst[$i]; $lst[$i] = $smallest; $lst[$index] = $temp; } echo ( implode(" ", $lst)); } } //linearSearch( $list, 3 ); function linearSearch( array $lst, $target ) { $numList = count( $lst ); for( $i=0; $i < $numList; $i++ ) { if( $lst[$i] == $target ) { echo "Found $target at $i\n"; } } } //factoral(6); function factoral( $n ) { if( $n == 1 ) { return 1; } echo $n * factoral( $n -1 ); } function chessboard() { for($i=0; $i<6; $i++) { echo "$i X0 :"; for($j=0; $j<$i; $j++) { echo "*"; } echo "\n"; } } //chessboard();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/knqkf
function name:  (null)
number of ops:  8
compiled vars:  !0 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        INIT_FCALL_BY_NAME                                       'bubbleSort'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   30     4        INIT_FCALL_BY_NAME                                       'selectionSort'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
  101     7      > RETURN                                                   1

Function bubblesort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 7
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 4
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 7
Branch analysis from position: 26
Branch analysis from position: 7
Branch analysis from position: 22
filename:       /in/knqkf
function name:  bubbleSort
number of ops:  34
compiled vars:  !0 = $lst, !1 = $numList, !2 = $swapped, !3 = $i, !4 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        COUNT                                            ~5      !0
          2        ASSIGN                                                   !1, ~5
   10     3        ASSIGN                                                   !2, <false>
   13     4    >   ASSIGN                                                   !2, <false>
   14     5        ASSIGN                                                   !3, 0
          6      > JMP                                                      ->23
   16     7    >   FETCH_DIM_R                                      ~10     !0, !3
          8        ADD                                              ~11     !3, 1
          9        FETCH_DIM_R                                      ~12     !0, ~11
         10        IS_SMALLER                                               ~12, ~10
         11      > JMPZ                                                     ~13, ->22
   17    12    >   FETCH_DIM_R                                      ~14     !0, !3
         13        ASSIGN                                                   !4, ~14
   18    14        ADD                                              ~17     !3, 1
         15        FETCH_DIM_R                                      ~18     !0, ~17
         16        ASSIGN_DIM                                               !0, !3
         17        OP_DATA                                                  ~18
   20    18        ADD                                              ~19     !3, 1
         19        ASSIGN_DIM                                               !0, ~19
         20        OP_DATA                                                  !4
   21    21        ASSIGN                                                   !2, <true>
   14    22    >   PRE_INC                                                  !3
         23    >   SUB                                              ~23     !1, 1
         24        IS_SMALLER                                               !3, ~23
         25      > JMPNZ                                                    ~24, ->7
   24    26    >   BOOL                                             ~25     !2
         27      > JMPNZ                                                    ~25, ->4
   26    28    >   INIT_FCALL                                               'implode'
         29        SEND_VAL                                                 '+'
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                         $26     
         32        ECHO                                                     $26
   27    33      > RETURN                                                   null

End of function bubblesort

Function selectionsort:
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 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 10
Branch analysis from position: 25
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: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 10
Branch analysis from position: 25
Branch analysis from position: 10
Branch analysis from position: 16
filename:       /in/knqkf
function name:  selectionSort
number of ops:  34
compiled vars:  !0 = $lst, !1 = $numList, !2 = $i, !3 = $index, !4 = $smallest, !5 = $j, !6 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   35     1        COUNT                                            ~7      !0
          2        ASSIGN                                                   !1, ~7
   36     3        ASSIGN                                                   !2, 0
          4      > JMP                                                      ->31
   38     5    >   ASSIGN                                                   !3, 0
   39     6        FETCH_DIM_R                                      ~11     !0, !2
          7        ASSIGN                                                   !4, ~11
   41     8        ASSIGN                                                   !5, !2
          9      > JMP                                                      ->23
   43    10    >   FETCH_DIM_R                                      ~14     !0, !5
         11        IS_SMALLER                                               ~14, !4
         12      > JMPZ                                                     ~15, ->16
   45    13    >   FETCH_DIM_R                                      ~16     !0, !5
         14        ASSIGN                                                   !4, ~16
   46    15        ASSIGN                                                   !3, !5
   48    16    >   FETCH_DIM_R                                      ~19     !0, !2
         17        ASSIGN                                                   !6, ~19
   49    18        ASSIGN_DIM                                               !0, !2
         19        OP_DATA                                                  !4
   50    20        ASSIGN_DIM                                               !0, !3
         21        OP_DATA                                                  !6
   41    22        PRE_INC                                                  !5
         23    >   IS_SMALLER                                               !5, !1
         24      > JMPNZ                                                    ~24, ->10
   52    25    >   INIT_FCALL                                               'implode'
         26        SEND_VAL                                                 '+'
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $25     
         29        ECHO                                                     $25
   36    30        PRE_INC                                                  !2
         31    >   IS_SMALLER                                               !2, !1
         32      > JMPNZ                                                    ~27, ->5
   54    33    > > RETURN                                                   null

End of function selectionsort

Function linearsearch:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 6
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 6
Branch analysis from position: 18
Branch analysis from position: 6
Branch analysis from position: 15
filename:       /in/knqkf
function name:  linearSearch
number of ops:  19
compiled vars:  !0 = $lst, !1 = $target, !2 = $numList, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   63     2        COUNT                                            ~4      !0
          3        ASSIGN                                                   !2, ~4
   65     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->16
   67     6    >   FETCH_DIM_R                                      ~7      !0, !3
          7        IS_EQUAL                                                 !1, ~7
          8      > JMPZ                                                     ~8, ->15
   69     9    >   ROPE_INIT                                     5  ~10     'Found+'
         10        ROPE_ADD                                      1  ~10     ~10, !1
         11        ROPE_ADD                                      2  ~10     ~10, '+at+'
         12        ROPE_ADD                                      3  ~10     ~10, !3
         13        ROPE_END                                      4  ~9      ~10, '%0A'
         14        ECHO                                                     ~9
   65    15    >   PRE_INC                                                  !3
         16    >   IS_SMALLER                                               !3, !2
         17      > JMPNZ                                                    ~14, ->6
   72    18    > > RETURN                                                   null

End of function linearsearch

Function factoral:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/knqkf
function name:  factoral
number of ops:  11
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   80     1        IS_EQUAL                                                 !0, 1
          2      > JMPZ                                                     ~1, ->4
   82     3    > > RETURN                                                   1
   85     4    >   INIT_FCALL_BY_NAME                                       'factoral'
          5        SUB                                              ~2      !0, 1
          6        SEND_VAL_EX                                              ~2
          7        DO_FCALL                                      0  $3      
          8        MUL                                              ~4      !0, $3
          9        ECHO                                                     ~4
   86    10      > RETURN                                                   null

End of function factoral

Function chessboard:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 7
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 2
Branch analysis from position: 15
Branch analysis from position: 2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 7
Branch analysis from position: 11
Branch analysis from position: 7
filename:       /in/knqkf
function name:  chessboard
number of ops:  16
compiled vars:  !0 = $i, !1 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   90     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->13
   92     2    >   NOP                                                      
          3        FAST_CONCAT                                      ~3      !0, '+X0+%3A'
          4        ECHO                                                     ~3
   93     5        ASSIGN                                                   !1, 0
          6      > JMP                                                      ->9
   95     7    >   ECHO                                                     '%2A'
   93     8        PRE_INC                                                  !1
          9    >   IS_SMALLER                                               !1, !0
         10      > JMPNZ                                                    ~6, ->7
   97    11    >   ECHO                                                     '%0A'
   90    12        PRE_INC                                                  !0
         13    >   IS_SMALLER                                               !0, 6
         14      > JMPNZ                                                    ~8, ->2
   99    15    > > RETURN                                                   null

End of function chessboard

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.63 ms | 1408 KiB | 15 Q