3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array[] = array ( "weight" => "20" ); $array[] = array ( "weight" => "15" ); $array[] = array( "weight" =>"40" ); $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 = 18, Position 2 = 36
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 36
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/eAitC
function name:  (null)
number of ops:  41
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        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'weight'
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !1, $8
   18    11        INIT_FCALL                                               'sort'
         12        SEND_REF                                                 !1
         13        DO_ICALL                                                 
   20    14        ASSIGN                                                   !2, 0
   21    15        ASSIGN_DIM                                               !3, 0
         16        OP_DATA                                                  <array>
   22    17      > FE_RESET_R                                       $13     !1, ->36
         18    > > FE_FETCH_R                                               $13, !4, ->36
   23    19    >   INIT_FCALL                                               'array_sum'
         20        FETCH_DIM_R                                      ~14     !3, !2
         21        SEND_VAL                                                 ~14
         22        DO_ICALL                                         $15     
         23        ADD                                              ~16     $15, !4
         24        IS_SMALLER                                               ~16, 50
         25      > JMPZ                                                     ~17, ->30
   24    26    >   FETCH_DIM_W                                      $18     !3, !2
         27        ASSIGN_DIM                                               $18
         28        OP_DATA                                                  !4
         29      > JMP                                                      ->35
   26    30    >   PRE_INC                                                  !2
   27    31        CAST                                          4  ~23     !4
         32        FETCH_DIM_W                                      $21     !3, !2
         33        ASSIGN_DIM                                               $21
         34        OP_DATA                                                  ~23
   22    35    > > JMP                                                      ->18
         36    >   FE_FREE                                                  $13
   31    37        INIT_FCALL                                               'var_dump'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                                 
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.73 ms | 1411 KiB | 21 Q