3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_random($arr, $num = 1) { shuffle($arr); $r = array(); for ($i = 0; $i < $num; $i++) { $r[] = $arr[$i]; } return $num == 1 ? $r[0] : $r; } $a = array("apple", "banana", "cherry"); print_r(array_random($a)); //print_r(array_random($a, 2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j4sZg
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'array_random'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   14     7      > RETURN                                                   1

Function array_random:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/j4sZg
function name:  array_random
number of ops:  22
compiled vars:  !0 = $arr, !1 = $num, !2 = $r, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
    3     2        INIT_FCALL                                               'shuffle'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
    5     5        ASSIGN                                                   !2, <array>
    6     6        ASSIGN                                                   !3, 0
          7      > JMP                                                      ->12
    7     8    >   FETCH_DIM_R                                      ~8      !0, !3
          9        ASSIGN_DIM                                               !2
         10        OP_DATA                                                  ~8
    6    11        PRE_INC                                                  !3
         12    >   IS_SMALLER                                               !3, !1
         13      > JMPNZ                                                    ~10, ->8
    9    14    >   IS_EQUAL                                                 !1, 1
         15      > JMPZ                                                     ~11, ->19
         16    >   FETCH_DIM_R                                      ~12     !2, 0
         17        QM_ASSIGN                                        ~13     ~12
         18      > JMP                                                      ->20
         19    >   QM_ASSIGN                                        ~13     !2
         20    > > RETURN                                                   ~13
   10    21*     > RETURN                                                   null

End of function array_random

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.97 ms | 1399 KiB | 18 Q