3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRandWithStipulations(int $total, int $count, array $scope): array { if ($scope[0] > $scope[1]) { throw new Exception('Argument 3 (\$scope) is expected to contain a minimum integer then a maximum integer.'); } if ($scope[1] * $count < $total) { throw new Exception('Arguments 2 (\$count) and 3 (\$scope) cannot satisfy argument 1 (\$total).'); } $result = []; for ($x = 1; $x < $count; ++$x) { // count - 1 iterations $scope[0] = max($scope[0], $total - ($scope[1] * ($count - $x))); $scope[1] = min($scope[1], $total - ($scope[0] * ($count - $x))); $rand = rand(...$scope); $result[] = $rand; $total -= $rand; } $result[] = $total; return $result; } var_export(getRandWithStipulations(130, 3, [23, 70]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YEo8s
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'var_export'
          1        INIT_FCALL                                               'getrandwithstipulations'
          2        SEND_VAL                                                 130
          3        SEND_VAL                                                 3
          4        SEND_VAL                                                 <array>
          5        DO_FCALL                                      0  $0      
          6        SEND_VAR                                                 $0
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function getrandwithstipulations:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 22
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 55, Position 2 = 22
Branch analysis from position: 55
Branch analysis from position: 22
filename:       /in/YEo8s
function name:  getRandWithStipulations
number of ops:  61
compiled vars:  !0 = $total, !1 = $count, !2 = $scope, !3 = $result, !4 = $x, !5 = $rand
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    5     3        FETCH_DIM_R                                      ~6      !2, 0
          4        FETCH_DIM_R                                      ~7      !2, 1
          5        IS_SMALLER                                               ~7, ~6
          6      > JMPZ                                                     ~8, ->11
    6     7    >   NEW                                              $9      'Exception'
          8        SEND_VAL_EX                                              'Argument+3+%28%5C%24scope%29+is+expected+to+contain+a+minimum+integer+then+a+maximum+integer.'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $9
    8    11    >   FETCH_DIM_R                                      ~11     !2, 1
         12        MUL                                              ~12     !1, ~11
         13        IS_SMALLER                                               ~12, !0
         14      > JMPZ                                                     ~13, ->19
    9    15    >   NEW                                              $14     'Exception'
         16        SEND_VAL_EX                                              'Arguments+2+%28%5C%24count%29+and+3+%28%5C%24scope%29+cannot+satisfy+argument+1+%28%5C%24total%29.'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $14
   11    19    >   ASSIGN                                                   !3, <array>
   12    20        ASSIGN                                                   !4, 1
         21      > JMP                                                      ->53
   13    22    >   INIT_FCALL                                               'max'
         23        FETCH_DIM_R                                      ~19     !2, 0
         24        SEND_VAL                                                 ~19
         25        FETCH_DIM_R                                      ~20     !2, 1
         26        SUB                                              ~21     !1, !4
         27        MUL                                              ~22     ~20, ~21
         28        SUB                                              ~23     !0, ~22
         29        SEND_VAL                                                 ~23
         30        DO_ICALL                                         $24     
         31        ASSIGN_DIM                                               !2, 0
         32        OP_DATA                                                  $24
   14    33        INIT_FCALL                                               'min'
         34        FETCH_DIM_R                                      ~26     !2, 1
         35        SEND_VAL                                                 ~26
         36        FETCH_DIM_R                                      ~27     !2, 0
         37        SUB                                              ~28     !1, !4
         38        MUL                                              ~29     ~27, ~28
         39        SUB                                              ~30     !0, ~29
         40        SEND_VAL                                                 ~30
         41        DO_ICALL                                         $31     
         42        ASSIGN_DIM                                               !2, 1
         43        OP_DATA                                                  $31
   15    44        INIT_FCALL                                               'rand'
         45        SEND_UNPACK                                              !2
         46        CHECK_UNDEF_ARGS                                         
         47        DO_ICALL                                         $32     
         48        ASSIGN                                                   !5, $32
   16    49        ASSIGN_DIM                                               !3
         50        OP_DATA                                                  !5
   17    51        ASSIGN_OP                                     2          !0, !5
   12    52        PRE_INC                                                  !4
         53    >   IS_SMALLER                                               !4, !1
         54      > JMPNZ                                                    ~37, ->22
   19    55    >   ASSIGN_DIM                                               !3
         56        OP_DATA                                                  !0
   20    57        VERIFY_RETURN_TYPE                                       !3
         58      > RETURN                                                   !3
   21    59*       VERIFY_RETURN_TYPE                                       
         60*     > RETURN                                                   null

End of function getrandwithstipulations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
123.3 ms | 1010 KiB | 18 Q