3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => 50, 1 => 200, 2 => 75, 3 => 150, 4 => 100, 5 => 125, 6 => 150, 7 => 300, 8 => 300, 9 => 300, 10 => 300, 11 => 300, 12 => 300, 13 => 300, 14 => 300, 15 => 300, ]; function consolidate(array $array, int $capacity = 500): array { arsort($array); $bins = [[]]; foreach ($array as $value) { $added = false; foreach ($bins as &$bin) { if ($capacity >= (array_sum($bin) + $value)) { $bin[] = $value; $added = true; continue 2; } } if (!$added) { $bins[] = [$value]; } } return array_map('array_sum', array_filter($bins)); } var_export(consolidate($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8pJQN
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   44     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'consolidate'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function consolidate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 30
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 30
Branch analysis from position: 8
2 jumps found. (Code = 125) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 126) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 29
Branch analysis from position: 23
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/8pJQN
function name:  consolidate
number of ops:  42
compiled vars:  !0 = $array, !1 = $capacity, !2 = $bins, !3 = $value, !4 = $added, !5 = $bin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      500
   24     2        INIT_FCALL                                               'arsort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   26     5        ASSIGN                                                   !2, <array>
   27     6      > FE_RESET_R                                       $8      !0, ->30
          7    > > FE_FETCH_R                                               $8, !3, ->30
   28     8    >   ASSIGN                                                   !4, <false>
   29     9      > FE_RESET_RW                                      $10     !2, ->23
         10    > > FE_FETCH_RW                                              $10, !5, ->23
   30    11    >   INIT_FCALL                                               'array_sum'
         12        SEND_VAR                                                 !5
         13        DO_ICALL                                         $11     
         14        ADD                                              ~12     $11, !3
         15        IS_SMALLER_OR_EQUAL                                      ~12, !1
         16      > JMPZ                                                     ~13, ->22
   31    17    >   ASSIGN_DIM                                               !5
         18        OP_DATA                                                  !3
   32    19        ASSIGN                                                   !4, <true>
   33    20        FE_FREE                                                  $10
         21      > JMP                                                      ->7
   29    22    > > JMP                                                      ->10
         23    >   FE_FREE                                                  $10
   36    24        BOOL_NOT                                         ~16     !4
         25      > JMPZ                                                     ~16, ->29
   37    26    >   INIT_ARRAY                                       ~18     !3
         27        ASSIGN_DIM                                               !2
         28        OP_DATA                                                  ~18
   27    29    > > JMP                                                      ->7
         30    >   FE_FREE                                                  $8
   41    31        INIT_FCALL                                               'array_map'
         32        SEND_VAL                                                 'array_sum'
         33        INIT_FCALL                                               'array_filter'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                         $19     
         36        SEND_VAR                                                 $19
         37        DO_ICALL                                         $20     
         38        VERIFY_RETURN_TYPE                                       $20
         39      > RETURN                                                   $20
   42    40*       VERIFY_RETURN_TYPE                                       
         41*     > RETURN                                                   null

End of function consolidate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.4 ms | 1403 KiB | 24 Q