3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_rand_cryptographically_secure(array $array): int|string { if (!$array) { throw new ValueError ('Argument #1 ($array) cannot be empty'); } return key(array_slice($array, random_int(0, count($array) - 1), 1, true)); } $tests = [ [5, 6, 7], ['a' => 1, 'b' => 2, 'c' => 3], ['zero', 4 => 'four', 9 => 'nine'] ]; foreach ($tests as $test) { echo array_rand_cryptographically_secure($test) . "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/s8oa4
function name:  (null)
number of ops:  11
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, <array>
   15     1      > FE_RESET_R                                       $3      !0, ->9
          2    > > FE_FETCH_R                                               $3, !1, ->9
   16     3    >   INIT_FCALL                                               'array_rand_cryptographically_secure'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   15     8      > JMP                                                      ->2
          9    >   FE_FREE                                                  $3
   17    10      > RETURN                                                   1

Function array_rand_cryptographically_secure:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s8oa4
function name:  array_rand_cryptographically_secure
number of ops:  26
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        BOOL_NOT                                         ~1      !0
          2      > JMPZ                                                     ~1, ->7
    5     3    >   NEW                                              $2      'ValueError'
          4        SEND_VAL_EX                                              'Argument+%231+%28%24array%29+cannot+be+empty'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $2
    7     7    >   INIT_FCALL                                               'key'
          8        INIT_FCALL                                               'array_slice'
          9        SEND_VAR                                                 !0
         10        INIT_FCALL                                               'random_int'
         11        SEND_VAL                                                 0
         12        COUNT                                            ~4      !0
         13        SUB                                              ~5      ~4, 1
         14        SEND_VAL                                                 ~5
         15        DO_ICALL                                         $6      
         16        SEND_VAR                                                 $6
         17        SEND_VAL                                                 1
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $7      
         20        SEND_VAR                                                 $7
         21        DO_ICALL                                         $8      
         22        VERIFY_RETURN_TYPE                                       $8
         23      > RETURN                                                   $8
    8    24*       VERIFY_RETURN_TYPE                                       
         25*     > RETURN                                                   null

End of function array_rand_cryptographically_secure

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.15 ms | 1403 KiB | 20 Q