3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array[] = array ( "weight" => "20" ); $array[] = array ( "weight" => "15" ); $array[] = array( "weight" =>"40" ); $array[] = array( "weight" =>"15" ); $array[] = array( "weight" =>"17" ); $array[] = array( "weight" =>"49" ); $array[] = array( "weight" =>"55" ); $arr = array_column($array, "weight"); sort($arr); $i= 0; $new[0]= []; foreach($arr as $val){ if(array_sum($new[$i]) + $val <50){ $new[$i][] = $val; }else{ $i++; $new[$i][] = (int) $val; } } var_dump($new);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 44
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 44
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/FUFQA
function name:  (null)
number of ops:  49
compiled vars:  !0 = $array, !1 = $arr, !2 = $i, !3 = $new, !4 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN_DIM                                               !0
    6     1        OP_DATA                                                  <array>
    8     2        ASSIGN_DIM                                               !0
   10     3        OP_DATA                                                  <array>
   13     4        ASSIGN_DIM                                               !0
   14     5        OP_DATA                                                  <array>
   17     6        ASSIGN_DIM                                               !0
   18     7        OP_DATA                                                  <array>
   20     8        ASSIGN_DIM                                               !0
   21     9        OP_DATA                                                  <array>
   23    10        ASSIGN_DIM                                               !0
   24    11        OP_DATA                                                  <array>
   26    12        ASSIGN_DIM                                               !0
   27    13        OP_DATA                                                  <array>
   30    14        INIT_FCALL                                               'array_column'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 'weight'
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !1, $12
   31    19        INIT_FCALL                                               'sort'
         20        SEND_REF                                                 !1
         21        DO_ICALL                                                 
   33    22        ASSIGN                                                   !2, 0
   34    23        ASSIGN_DIM                                               !3, 0
         24        OP_DATA                                                  <array>
   35    25      > FE_RESET_R                                       $17     !1, ->44
         26    > > FE_FETCH_R                                               $17, !4, ->44
   36    27    >   INIT_FCALL                                               'array_sum'
         28        FETCH_DIM_R                                      ~18     !3, !2
         29        SEND_VAL                                                 ~18
         30        DO_ICALL                                         $19     
         31        ADD                                              ~20     $19, !4
         32        IS_SMALLER                                               ~20, 50
         33      > JMPZ                                                     ~21, ->38
   37    34    >   FETCH_DIM_W                                      $22     !3, !2
         35        ASSIGN_DIM                                               $22
         36        OP_DATA                                                  !4
         37      > JMP                                                      ->43
   39    38    >   PRE_INC                                                  !2
   40    39        CAST                                          4  ~27     !4
         40        FETCH_DIM_W                                      $25     !3, !2
         41        ASSIGN_DIM                                               $25
         42        OP_DATA                                                  ~27
   35    43    > > JMP                                                      ->26
         44    >   FE_FREE                                                  $17
   44    45        INIT_FCALL                                               'var_dump'
         46        SEND_VAR                                                 !3
         47        DO_ICALL                                                 
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.74 ms | 1411 KiB | 21 Q