3v4l.org

run code in 300+ PHP versions simultaneously
<?php $max = 111; //265; $items = [50, 45, 30, 60, 70, 80]; function nextFitDecreasing(array $items, int $max): array { rsort($items); $result = []; foreach ($items as $item) { if (!isset($pallet) || (array_sum($pallet) + $item) > $max) { unset($pallet); $result[] = &$pallet; } $pallet[] = $item; } return $result; } function firstFitDecreasing(array $items, int $max): array { rsort($items); $result = []; foreach ($items as $item) { foreach ($result as &$pallet) { if (array_sum($pallet) + $item <= $max) { $pallet[] = $item; continue 2; } } $result[] = [$item]; } return $result; } var_export(nextFitDecreasing($items, $max)); echo "\n---\n"; var_export(firstFitDecreasing($items, $max));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QSP6a
function name:  (null)
number of ops:  18
compiled vars:  !0 = $max, !1 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 111
    4     1        ASSIGN                                                   !1, <array>
   36     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'nextfitdecreasing'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   37     9        ECHO                                                     '%0A---%0A'
   38    10        INIT_FCALL                                               'var_export'
         11        INIT_FCALL                                               'firstfitdecreasing'
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !0
         14        DO_FCALL                                      0  $6      
         15        SEND_VAR                                                 $6
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function nextfitdecreasing:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
Branch analysis from position: 17
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/QSP6a
function name:  nextFitDecreasing
number of ops:  29
compiled vars:  !0 = $items, !1 = $max, !2 = $result, !3 = $item, !4 = $pallet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'rsort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
    9     5        ASSIGN                                                   !2, <array>
   10     6      > FE_RESET_R                                       $7      !0, ->24
          7    > > FE_FETCH_R                                               $7, !3, ->24
   11     8    >   ISSET_ISEMPTY_CV                                 ~8      !4
          9        BOOL_NOT                                         ~9      ~8
         10      > JMPNZ_EX                                         ~9      ~9, ->17
         11    >   INIT_FCALL                                               'array_sum'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $10     
         14        ADD                                              ~11     $10, !3
         15        IS_SMALLER                                       ~12     !1, ~11
         16        BOOL                                             ~9      ~12
         17    > > JMPZ                                                     ~9, ->21
   12    18    >   UNSET_CV                                                 !4
   13    19        FETCH_DIM_W                                      $13     !2
         20        ASSIGN_REF                                               $13, !4
   15    21    >   ASSIGN_DIM                                               !4
         22        OP_DATA                                                  !3
   10    23      > JMP                                                      ->7
         24    >   FE_FREE                                                  $7
   17    25        VERIFY_RETURN_TYPE                                       !2
         26      > RETURN                                                   !2
   18    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function nextfitdecreasing

Function firstfitdecreasing:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 26
Branch analysis from position: 8
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 21
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/QSP6a
function name:  firstFitDecreasing
number of ops:  31
compiled vars:  !0 = $items, !1 = $max, !2 = $result, !3 = $item, !4 = $pallet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        INIT_FCALL                                               'rsort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   23     5        ASSIGN                                                   !2, <array>
   24     6      > FE_RESET_R                                       $7      !0, ->26
          7    > > FE_FETCH_R                                               $7, !3, ->26
   25     8    > > FE_RESET_RW                                      $8      !2, ->21
          9    > > FE_FETCH_RW                                              $8, !4, ->21
   26    10    >   INIT_FCALL                                               'array_sum'
         11        SEND_VAR                                                 !4
         12        DO_ICALL                                         $9      
         13        ADD                                              ~10     $9, !3
         14        IS_SMALLER_OR_EQUAL                                      ~10, !1
         15      > JMPZ                                                     ~11, ->20
   27    16    >   ASSIGN_DIM                                               !4
         17        OP_DATA                                                  !3
   28    18        FE_FREE                                                  $8
         19      > JMP                                                      ->7
   25    20    > > JMP                                                      ->9
         21    >   FE_FREE                                                  $8
   31    22        INIT_ARRAY                                       ~14     !3
         23        ASSIGN_DIM                                               !2
         24        OP_DATA                                                  ~14
   24    25      > JMP                                                      ->7
         26    >   FE_FREE                                                  $7
   33    27        VERIFY_RETURN_TYPE                                       !2
         28      > RETURN                                                   !2
   34    29*       VERIFY_RETURN_TYPE                                       
         30*     > RETURN                                                   null

End of function firstfitdecreasing

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.89 ms | 1013 KiB | 18 Q