3v4l.org

run code in 300+ 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 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 4
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 4
Branch analysis from position: 30
Branch analysis from position: 4
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
Branch analysis from position: 6
Branch analysis from position: 25
Branch analysis from position: 21
filename:       /in/oIDW0
function name:  uniqRand
number of ops:  32
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                                                      ->28
   13     4    >   ASSIGN                                                   !3, <false>
   14     5      > JMP                                                      ->25
   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, ->21
         15    >   INIT_FCALL                                               'in_array'
         16        SEND_VAR                                                 !4
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $13     
         19        BOOL_NOT                                         ~14     $13
         20        BOOL                                             ~12     ~14
         21    > > JMPZ                                                     ~12, ->25
   17    22    >   ASSIGN_DIM                                               !1, !2
         23        OP_DATA                                                  !4
   18    24        ASSIGN                                                   !3, <true>
   14    25    >   BOOL_NOT                                         ~17     !3
         26      > JMPNZ                                                    ~17, ->6
   12    27    >   PRE_INC                                                  !2
         28    >   IS_SMALLER                                               !2, !0
         29      > JMPNZ                                                    ~19, ->4
   23    30    > > RETURN                                                   !1
   24    31*     > RETURN                                                   null

End of function uniqrand

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.84 ms | 1403 KiB | 22 Q