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 { rsort($array); $bins = [0]; foreach ($array as $value) { foreach ($bins as &$bin) { if ($capacity >= $bin + $value) { $bin += $value; continue 2; } } $bins[] = $value; } return array_values(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/LHnY8
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>
   40     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 = 21
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/LHnY8
function name:  consolidate
number of ops:  32
compiled vars:  !0 = $array, !1 = $capacity, !2 = $bins, !3 = $value, !4 = $bin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      500
   24     2        INIT_FCALL                                               'rsort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   26     5        ASSIGN                                                   !2, <array>
   27     6      > FE_RESET_R                                       $7      !0, ->21
          7    > > FE_FETCH_R                                               $7, !3, ->21
   28     8    > > FE_RESET_RW                                      $8      !2, ->17
          9    > > FE_FETCH_RW                                              $8, !4, ->17
   29    10    >   ADD                                              ~9      !4, !3
         11        IS_SMALLER_OR_EQUAL                                      ~9, !1
         12      > JMPZ                                                     ~10, ->16
   30    13    >   ASSIGN_OP                                     1          !4, !3
   31    14        FE_FREE                                                  $8
         15      > JMP                                                      ->7
   28    16    > > JMP                                                      ->9
         17    >   FE_FREE                                                  $8
   34    18        ASSIGN_DIM                                               !2
         19        OP_DATA                                                  !3
   27    20      > JMP                                                      ->7
         21    >   FE_FREE                                                  $7
   37    22        INIT_FCALL                                               'array_values'
         23        INIT_FCALL                                               'array_filter'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                         $13     
         26        SEND_VAR                                                 $13
         27        DO_ICALL                                         $14     
         28        VERIFY_RETURN_TYPE                                       $14
         29      > RETURN                                                   $14
   38    30*       VERIFY_RETURN_TYPE                                       
         31*     > RETURN                                                   null

End of function consolidate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.35 ms | 1015 KiB | 18 Q