3v4l.org

run code in 500+ PHP versions simultaneously
<?php $order = 99; $sizes=[21,18,12,6]; $b = [21 => 0, 18 => 0, 12 => 0, 6 => 0]; // number of 21 boxes possible if($order >= 21){ $b[21] = floor($order/21); $order -= $b[21]*21; } // if the remainder needs to be modified to be divisible on 6 while($order % 6 != 0){ if($b[21] > 0){ // remove one box of 21 and add the bottles back to the remainder $order += 21; $b[21]--; }else{ // if we run out of 21 boxes then the order is not possible. echo "order not possible"; exit; } } // split up the remainder on 18/12/6 boxes and remove empty boxes $b = array_filter(split_up($b, $order)); var_dump($b); function split_up($b, $order){ // number of 18 boxes possible if($order >= 18){ $b[18] = floor($order/18); $order -= $b[18]*18; } // number of 12 boxes possible if($order >= 12){ $b[12] = floor($order/12); $order -= $b[12]*12; } // number of 6 boxes possible if($order >= 6){ $b[6] = floor($order/6); $order -= $b[6]*6; } return $b; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 15
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 22
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 14
filename:       /in/EM9EF
function name:  (null)
number of ops:  40
compiled vars:  !0 = $order, !1 = $sizes, !2 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 99
    4     1        ASSIGN                                                       !1, <array>
    5     2        ASSIGN                                                       !2, <array>
    8     3        IS_SMALLER_OR_EQUAL                                          21, !0
          4      > JMPZ                                                         ~6, ->14
    9     5    >   INIT_FCALL                                                   'floor'
          6        DIV                                                  ~8      !0, 21
          7        SEND_VAL                                                     ~8
          8        DO_ICALL                                             $9      
          9        ASSIGN_DIM                                                   !2, 21
         10        OP_DATA                                                      $9
   10    11        FETCH_DIM_R                                          ~10     !2, 21
         12        MUL                                                  ~11     ~10, 21
         13        ASSIGN_OP                                         2          !0, ~11
   14    14    > > JMP                                                          ->25
   15    15    >   FETCH_DIM_R                                          ~13     !2, 21
         16        IS_SMALLER                                                   0, ~13
         17      > JMPZ                                                         ~14, ->22
   17    18    >   ASSIGN_OP                                         1          !0, 21
   18    19        FETCH_DIM_RW                                         $16     !2, 21
         20        PRE_DEC                                                      $16
   15    21      > JMP                                                          ->25
   21    22    >   ECHO                                                         'order+not+possible'
   22    23      > INIT_FCALL                                                   'exit'
         24*       DO_ICALL                                                     
   14    25    >   MOD                                                  ~19     !0, 6
         26        IS_NOT_EQUAL                                                 ~19, 0
         27      > JMPNZ                                                        ~20, ->15
   26    28    >   INIT_FCALL                                                   'array_filter'
         29        INIT_FCALL_BY_NAME                                           'split_up'
         30        SEND_VAR_EX                                                  !2
         31        SEND_VAR_EX                                                  !0
         32        DO_FCALL                                          0  $21     
         33        SEND_VAR                                                     $21
         34        DO_ICALL                                             $22     
         35        ASSIGN                                                       !2, $22
   28    36        INIT_FCALL                                                   'var_dump'
         37        SEND_VAR                                                     !2
         38        DO_ICALL                                                     
   47    39      > RETURN                                                       1

Function split_up:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 24
Branch analysis from position: 13
filename:       /in/EM9EF
function name:  split_up
number of ops:  37
compiled vars:  !0 = $b, !1 = $order
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   32     2        IS_SMALLER_OR_EQUAL                                          18, !1
          3      > JMPZ                                                         ~2, ->13
   33     4    >   INIT_FCALL                                                   'floor'
          5        DIV                                                  ~4      !1, 18
          6        SEND_VAL                                                     ~4
          7        DO_ICALL                                             $5      
          8        ASSIGN_DIM                                                   !0, 18
          9        OP_DATA                                                      $5
   34    10        FETCH_DIM_R                                          ~6      !0, 18
         11        MUL                                                  ~7      ~6, 18
         12        ASSIGN_OP                                         2          !1, ~7
   37    13    >   IS_SMALLER_OR_EQUAL                                          12, !1
         14      > JMPZ                                                         ~9, ->24
   38    15    >   INIT_FCALL                                                   'floor'
         16        DIV                                                  ~11     !1, 12
         17        SEND_VAL                                                     ~11
         18        DO_ICALL                                             $12     
         19        ASSIGN_DIM                                                   !0, 12
         20        OP_DATA                                                      $12
   39    21        FETCH_DIM_R                                          ~13     !0, 12
         22        MUL                                                  ~14     ~13, 12
         23        ASSIGN_OP                                         2          !1, ~14
   42    24    >   IS_SMALLER_OR_EQUAL                                          6, !1
         25      > JMPZ                                                         ~16, ->35
   43    26    >   INIT_FCALL                                                   'floor'
         27        DIV                                                  ~18     !1, 6
         28        SEND_VAL                                                     ~18
         29        DO_ICALL                                             $19     
         30        ASSIGN_DIM                                                   !0, 6
         31        OP_DATA                                                      $19
   44    32        FETCH_DIM_R                                          ~20     !0, 6
         33        MUL                                                  ~21     ~20, 6
         34        ASSIGN_OP                                         2          !1, ~21
   46    35    > > RETURN                                                       !0
   47    36*     > RETURN                                                       null

End of function split_up

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.64 ms | 2302 KiB | 17 Q