3v4l.org

run code in 500+ PHP versions simultaneously
<?php define('MAX_INT', 100); // fill array by unique values // @param int $n array size // @return array with randow unique values function uniqRand($n) { $ret = []; for($i = 0; $i < $n; $i++) { $unq = false; while($unq != true) { $v = rand(0, MAX_INT); if(!count($ret) || !in_array($v, $ret)) { $ret[$i] = $v; $unq = true; } } } return $ret; } // uniqRand(n int) int[] // uniqRand(5) -> [1,5,100,2,4] $ret = uniqRand(5); var_dump($ret);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oIDW0
function name:  (null)
number of ops:  12
compiled vars:  !0 = $ret
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'define'
          1        SEND_VAL                                                     'MAX_INT'
          2        SEND_VAL                                                     100
          3        DO_ICALL                                                     
   28     4        INIT_FCALL                                                   'uniqrand'
          5        SEND_VAL                                                     5
          6        DO_FCALL                                          0  $2      
          7        ASSIGN                                                       !0, $2
   29     8        INIT_FCALL                                                   'var_dump'
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                                     
         11      > RETURN                                                       1

Function uniqrand:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 4
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 6
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 4
Branch analysis from position: 27
Branch analysis from position: 4
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
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: 22
Branch analysis from position: 18
filename:       /in/oIDW0
function name:  uniqRand
number of ops:  29
compiled vars:  !0 = $n, !1 = $ret, !2 = $i, !3 = $unq, !4 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
   10     1        ASSIGN                                                       !1, <array>
   12     2        ASSIGN                                                       !2, 0
          3      > JMP                                                          ->25
   13     4    >   ASSIGN                                                       !3, <false>
   14     5      > JMP                                                          ->22
   15     6    >   INIT_FCALL                                                   'rand'
          7        SEND_VAL                                                     0
          8        FETCH_CONSTANT                                       ~8      'MAX_INT'
          9        SEND_VAL                                                     ~8
         10        DO_ICALL                                             $9      
         11        ASSIGN                                                       !4, $9
   16    12        COUNT                                                ~11     !1
         13        BOOL_NOT                                             ~12     ~11
         14      > JMPNZ_EX                                             ~12     ~12, ->18
         15    >   FRAMELESS_ICALL_2                in_array            ~13     !4, !1
         16        BOOL_NOT                                             ~14     ~13
         17        BOOL                                                 ~12     ~14
         18    > > JMPZ                                                         ~12, ->22
   17    19    >   ASSIGN_DIM                                                   !1, !2
         20        OP_DATA                                                      !4
   18    21        ASSIGN                                                       !3, <true>
   14    22    >   IS_NOT_EQUAL                                                 !3, <true>
         23      > JMPNZ                                                        ~17, ->6
   12    24    >   PRE_INC                                                      !2
         25    >   IS_SMALLER                                                   !2, !0
         26      > JMPNZ                                                        ~19, ->4
   23    27    > > RETURN                                                       !1
   24    28*     > RETURN                                                       null

End of function uniqrand

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.03 ms | 1352 KiB | 17 Q