3v4l.org

run code in 300+ PHP versions simultaneously
<?php function knapsackLight($value1, $weight1, $value2, $weight2, $maxW) { $result = []; $result[] = ['weight' => $weight1, 'value' => $value1]; $result[] = ['weight' => $weight2, 'value' => $value2]; $result[] = ['weight' => $weight1 + $weight2, 'value' => $value1 + $weight2]; $result = array_filter($result, function($v) use ($maxW) { return $v['weight'] <= $maxW; }); return max(array_column($result, 'value')); } var_dump(knapsackLight(10, 5, 6, 4, 8)); var_dump(knapsackLight(10, 5, 6, 5, 9));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EXpjC
function name:  (null)
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'knapsacklight'
          2        SEND_VAL                                                 10
          3        SEND_VAL                                                 5
          4        SEND_VAL                                                 6
          5        SEND_VAL                                                 4
          6        SEND_VAL                                                 8
          7        DO_FCALL                                      0  $0      
          8        SEND_VAR                                                 $0
          9        DO_ICALL                                                 
   17    10        INIT_FCALL                                               'var_dump'
         11        INIT_FCALL                                               'knapsacklight'
         12        SEND_VAL                                                 10
         13        SEND_VAL                                                 5
         14        SEND_VAL                                                 6
         15        SEND_VAL                                                 5
         16        SEND_VAL                                                 9
         17        DO_FCALL                                      0  $2      
         18        SEND_VAR                                                 $2
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function knapsacklight:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EXpjC
function name:  knapsackLight
number of ops:  36
compiled vars:  !0 = $value1, !1 = $weight1, !2 = $value2, !3 = $weight2, !4 = $maxW, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
    4     5        ASSIGN                                                   !5, <array>
    5     6        INIT_ARRAY                                       ~8      !1, 'weight'
          7        ADD_ARRAY_ELEMENT                                ~8      !0, 'value'
          8        ASSIGN_DIM                                               !5
          9        OP_DATA                                                  ~8
    6    10        INIT_ARRAY                                       ~10     !3, 'weight'
         11        ADD_ARRAY_ELEMENT                                ~10     !2, 'value'
         12        ASSIGN_DIM                                               !5
         13        OP_DATA                                                  ~10
    7    14        ADD                                              ~12     !1, !3
         15        INIT_ARRAY                                       ~13     ~12, 'weight'
         16        ADD                                              ~14     !0, !3
         17        ADD_ARRAY_ELEMENT                                ~13     ~14, 'value'
         18        ASSIGN_DIM                                               !5
         19        OP_DATA                                                  ~13
    9    20        INIT_FCALL                                               'array_filter'
         21        SEND_VAR                                                 !5
         22        DECLARE_LAMBDA_FUNCTION                          ~15     [0]
         23        BIND_LEXICAL                                             ~15, !4
   11    24        SEND_VAL                                                 ~15
    9    25        DO_ICALL                                         $16     
         26        ASSIGN                                                   !5, $16
   13    27        INIT_FCALL                                               'max'
         28        INIT_FCALL                                               'array_column'
         29        SEND_VAR                                                 !5
         30        SEND_VAL                                                 'value'
         31        DO_ICALL                                         $18     
         32        SEND_VAR                                                 $18
         33        DO_ICALL                                         $19     
         34      > RETURN                                                   $19
   14    35*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EXpjC
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $v, !1 = $maxW
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   10     2        FETCH_DIM_R                                      ~2      !0, 'weight'
          3        IS_SMALLER_OR_EQUAL                              ~3      ~2, !1
          4      > RETURN                                                   ~3
   11     5*     > RETURN                                                   null

End of Dynamic Function 0

End of function knapsacklight

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.03 ms | 1021 KiB | 19 Q