3v4l.org

run code in 300+ PHP versions simultaneously
<?php function putInArrayIfBig(&$array, $number) { //array is empty if(count($array) == 0) { array_push($array, $number); return; } //push new value, remove smallest for($i = 0; $i < count($array); $i++) { if($array[$i] < $number) { array_splice($array, $i, 0, $number); if(count($array) > 30) { //remove 31 item array_pop($array); } return; } } //if item not inserted and array not yet full if(count($array) < 30) { array_push($array, $number); return; } } $top30 = [9,8,7,6,4,3,2,1]; putInArrayIfBig($top30, 5); putInArrayIfBig($top30, 0); putInArrayIfBig($top30, 10); var_dump($top30); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jFWJU
function name:  (null)
number of ops:  17
compiled vars:  !0 = $top30
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   29     1        INIT_FCALL                                               'putinarrayifbig'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 5
          4        DO_FCALL                                      0          
   30     5        INIT_FCALL                                               'putinarrayifbig'
          6        SEND_REF                                                 !0
          7        SEND_VAL                                                 0
          8        DO_FCALL                                      0          
   31     9        INIT_FCALL                                               'putinarrayifbig'
         10        SEND_REF                                                 !0
         11        SEND_VAL                                                 10
         12        DO_FCALL                                      0          
   32    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                                 
   34    16      > RETURN                                                   1

Function putinarrayifbig:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 12
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 28
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 12
Branch analysis from position: 32
Branch analysis from position: 12
filename:       /in/jFWJU
function name:  putInArrayIfBig
number of ops:  41
compiled vars:  !0 = $array, !1 = $number, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        COUNT                                            ~3      !0
          3        IS_EQUAL                                                 ~3, 0
          4      > JMPZ                                                     ~4, ->10
    6     5    >   INIT_FCALL                                               'array_push'
          6        SEND_REF                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
    7     9      > RETURN                                                   null
   10    10    >   ASSIGN                                                   !2, 0
         11      > JMP                                                      ->29
   11    12    >   FETCH_DIM_R                                      ~7      !0, !2
         13        IS_SMALLER                                               ~7, !1
         14      > JMPZ                                                     ~8, ->28
   12    15    >   INIT_FCALL                                               'array_splice'
         16        SEND_REF                                                 !0
         17        SEND_VAR                                                 !2
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                                 
   13    21        COUNT                                            ~10     !0
         22        IS_SMALLER                                               30, ~10
         23      > JMPZ                                                     ~11, ->27
   14    24    >   INIT_FCALL                                               'array_pop'
         25        SEND_REF                                                 !0
         26        DO_ICALL                                                 
   16    27    > > RETURN                                                   null
   10    28    >   PRE_INC                                                  !2
         29    >   COUNT                                            ~14     !0
         30        IS_SMALLER                                               !2, ~14
         31      > JMPNZ                                                    ~15, ->12
   20    32    >   COUNT                                            ~16     !0
         33        IS_SMALLER                                               ~16, 30
         34      > JMPZ                                                     ~17, ->40
   21    35    >   INIT_FCALL                                               'array_push'
         36        SEND_REF                                                 !0
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                                 
   22    39      > RETURN                                                   null
   24    40    > > RETURN                                                   null

End of function putinarrayifbig

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.29 ms | 1403 KiB | 24 Q