3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRandomTo($num){ $arr = array(); do { $arr = rand(1, $num - array_sum($arr)); } while (array_sum($arr) < $num); return $arr; } print_r(getRandomTo(12));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YCShp
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'getrandomto'
          2        SEND_VAL                                                 12
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function getrandomto:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
filename:       /in/YCShp
function name:  getRandomTo
number of ops:  18
compiled vars:  !0 = $num, !1 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    6     2    >   INIT_FCALL                                               'rand'
          3        SEND_VAL                                                 1
          4        INIT_FCALL                                               'array_sum'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        SUB                                              ~4      !0, $3
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !1, $5
    7    11        INIT_FCALL                                               'array_sum'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $7      
         14        IS_SMALLER                                               $7, !0
         15      > JMPNZ                                                    ~8, ->2
    8    16    > > RETURN                                                   !1
    9    17*     > RETURN                                                   null

End of function getrandomto

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.25 ms | 938 KiB | 21 Q