3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_missing($numeros) { $numeros = array_filter(array_unique($numeros), function ($v) { return $v >= 0; }); sort($numeros); for ($i = 1; $i < count($numeros); $i++) { if ($numeros[$i] != $numeros[$i-1] + 1) { return $numeros[$i-1] + 1; } } // all numbers consecutive return false; } $m = find_missing(array(1, 3, 6, 4)); echo ($m === false) ? "array is consecutive\n" : "$m is the first missing number\n"; $m = find_missing(array(-1,9, 0, 8)); echo ($m === false) ? "array is consecutive\n" : "$m is the first missing number\n"; $m = find_missing(array(1,2,3,4,1,2,3,5,6,3,13,4,6,5, -1, -2)); echo ($m === false) ? "array is consecutive\n" : "$m is the first missing number\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
Branch analysis from position: 32
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
Branch analysis from position: 20
filename:       /in/9Qfpp
function name:  (null)
number of ops:  37
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'find_missing'
          1        SEND_VAL                                                 <array>
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   14     4        TYPE_CHECK                                    4          !0
          5      > JMPZ                                                     ~3, ->8
          6    >   QM_ASSIGN                                        ~4      'array+is+consecutive%0A'
          7      > JMP                                                      ->11
          8    >   NOP                                                      
          9        FAST_CONCAT                                      ~5      !0, '+is+the+first+missing+number%0A'
         10        QM_ASSIGN                                        ~4      ~5
         11    >   ECHO                                                     ~4
   15    12        INIT_FCALL                                               'find_missing'
         13        SEND_VAL                                                 <array>
         14        DO_FCALL                                      0  $6      
         15        ASSIGN                                                   !0, $6
   16    16        TYPE_CHECK                                    4          !0
         17      > JMPZ                                                     ~8, ->20
         18    >   QM_ASSIGN                                        ~9      'array+is+consecutive%0A'
         19      > JMP                                                      ->23
         20    >   NOP                                                      
         21        FAST_CONCAT                                      ~10     !0, '+is+the+first+missing+number%0A'
         22        QM_ASSIGN                                        ~9      ~10
         23    >   ECHO                                                     ~9
   17    24        INIT_FCALL                                               'find_missing'
         25        SEND_VAL                                                 <array>
         26        DO_FCALL                                      0  $11     
         27        ASSIGN                                                   !0, $11
   18    28        TYPE_CHECK                                    4          !0
         29      > JMPZ                                                     ~13, ->32
         30    >   QM_ASSIGN                                        ~14     'array+is+consecutive%0A'
         31      > JMP                                                      ->35
         32    >   NOP                                                      
         33        FAST_CONCAT                                      ~15     !0, '+is+the+first+missing+number%0A'
         34        QM_ASSIGN                                        ~14     ~15
         35    >   ECHO                                                     ~14
         36      > RETURN                                                   1

Function find_missing:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 15
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 15
Branch analysis from position: 29
Branch analysis from position: 15
filename:       /in/9Qfpp
function name:  find_missing
number of ops:  31
compiled vars:  !0 = $numeros, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'array_filter'
          2        INIT_FCALL                                               'array_unique'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F9Qfpp%3A3%240'
          7        SEND_VAL                                                 ~3
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !0, $4
    4    10        INIT_FCALL                                               'sort'
         11        SEND_REF                                                 !0
         12        DO_ICALL                                                 
    5    13        ASSIGN                                                   !1, 1
         14      > JMP                                                      ->26
    6    15    >   FETCH_DIM_R                                      ~8      !0, !1
         16        SUB                                              ~9      !1, 1
         17        FETCH_DIM_R                                      ~10     !0, ~9
         18        ADD                                              ~11     ~10, 1
         19        IS_NOT_EQUAL                                             ~8, ~11
         20      > JMPZ                                                     ~12, ->25
    7    21    >   SUB                                              ~13     !1, 1
         22        FETCH_DIM_R                                      ~14     !0, ~13
         23        ADD                                              ~15     ~14, 1
         24      > RETURN                                                   ~15
    5    25    >   PRE_INC                                                  !1
         26    >   COUNT                                            ~17     !0
         27        IS_SMALLER                                               !1, ~17
         28      > JMPNZ                                                    ~18, ->15
   11    29    > > RETURN                                                   <false>
   12    30*     > RETURN                                                   null

End of function find_missing

Function %00%7Bclosure%7D%2Fin%2F9Qfpp%3A3%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9Qfpp
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        IS_SMALLER_OR_EQUAL                              ~1      0, !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F9Qfpp%3A3%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.36 ms | 1417 KiB | 22 Q