3v4l.org

run code in 300+ PHP versions simultaneously
<?php function knapsackLight($value1, $weight1, $value2, $weight2, $maxW) { $results[0] = $maxW >= $weight1 && $value1 ? $value1 : null; $results[1] = $maxW >= $weight2 && $value2 ? $value2 : null; $results[2] = $maxW >= $weight1 + $weight2 && $value1 + $value2 ? $value1 + $value2 : null; return max($results[0], $results[1], $results[2]); } 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/0EBlC
function name:  (null)
number of ops:  21
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     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                                                 
   11    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
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
Branch analysis from position: 28
Branch analysis from position: 17
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
Branch analysis from position: 17
Branch analysis from position: 8
filename:       /in/0EBlC
function name:  knapsackLight
number of ops:  45
compiled vars:  !0 = $value1, !1 = $weight1, !2 = $value2, !3 = $weight2, !4 = $maxW, !5 = $results
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        IS_SMALLER_OR_EQUAL                              ~7      !1, !4
          6      > JMPZ_EX                                          ~7      ~7, ->8
          7    >   BOOL                                             ~7      !0
          8    > > JMPZ                                                     ~7, ->11
          9    >   QM_ASSIGN                                        ~8      !0
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~8      null
         12    >   ASSIGN_DIM                                               !5, 0
         13        OP_DATA                                                  ~8
    5    14        IS_SMALLER_OR_EQUAL                              ~10     !3, !4
         15      > JMPZ_EX                                          ~10     ~10, ->17
         16    >   BOOL                                             ~10     !2
         17    > > JMPZ                                                     ~10, ->20
         18    >   QM_ASSIGN                                        ~11     !2
         19      > JMP                                                      ->21
         20    >   QM_ASSIGN                                        ~11     null
         21    >   ASSIGN_DIM                                               !5, 1
         22        OP_DATA                                                  ~11
    6    23        ADD                                              ~13     !1, !3
         24        IS_SMALLER_OR_EQUAL                              ~14     ~13, !4
         25      > JMPZ_EX                                          ~14     ~14, ->28
         26    >   ADD                                              ~15     !0, !2
         27        BOOL                                             ~14     ~15
         28    > > JMPZ                                                     ~14, ->32
         29    >   ADD                                              ~16     !0, !2
         30        QM_ASSIGN                                        ~17     ~16
         31      > JMP                                                      ->33
         32    >   QM_ASSIGN                                        ~17     null
         33    >   ASSIGN_DIM                                               !5, 2
         34        OP_DATA                                                  ~17
    7    35        INIT_FCALL                                               'max'
         36        FETCH_DIM_R                                      ~18     !5, 0
         37        SEND_VAL                                                 ~18
         38        FETCH_DIM_R                                      ~19     !5, 1
         39        SEND_VAL                                                 ~19
         40        FETCH_DIM_R                                      ~20     !5, 2
         41        SEND_VAL                                                 ~20
         42        DO_ICALL                                         $21     
         43      > RETURN                                                   $21
    8    44*     > RETURN                                                   null

End of function knapsacklight

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.3 ms | 1445 KiB | 17 Q