3v4l.org

run code in 300+ PHP versions simultaneously
<?php function knapsackLight($value1, $weight1, $value2, $weight2, $maxW) { $results[0] = $maxW >= $weight1 ? $value1 : 0; $results[1] = $maxW >= $weight2 ? $value2 : 0; $results[2] = $maxW >= $weight1 + $weight2 ? $value1 + $value2 : 0; return max($results); } echo knapsackLight(10,5,6,4,8) . PHP_EOL; //10 echo knapsackLight(10,5,6,4,9) . PHP_EOL; //16 echo knapsackLight(5,3,7,4,6) . PHP_EOL; // 7
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nMc7e
function name:  (null)
number of ops:  28
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'knapsacklight'
          1        SEND_VAL                                                 10
          2        SEND_VAL                                                 5
          3        SEND_VAL                                                 6
          4        SEND_VAL                                                 4
          5        SEND_VAL                                                 8
          6        DO_FCALL                                      0  $0      
          7        CONCAT                                           ~1      $0, '%0A'
          8        ECHO                                                     ~1
   11     9        INIT_FCALL                                               'knapsacklight'
         10        SEND_VAL                                                 10
         11        SEND_VAL                                                 5
         12        SEND_VAL                                                 6
         13        SEND_VAL                                                 4
         14        SEND_VAL                                                 9
         15        DO_FCALL                                      0  $2      
         16        CONCAT                                           ~3      $2, '%0A'
         17        ECHO                                                     ~3
   12    18        INIT_FCALL                                               'knapsacklight'
         19        SEND_VAL                                                 5
         20        SEND_VAL                                                 3
         21        SEND_VAL                                                 7
         22        SEND_VAL                                                 4
         23        SEND_VAL                                                 6
         24        DO_FCALL                                      0  $4      
         25        CONCAT                                           ~5      $4, '%0A'
         26        ECHO                                                     ~5
         27      > RETURN                                                   1

Function knapsacklight:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
Branch analysis from position: 25
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
Branch analysis from position: 16
filename:       /in/nMc7e
function name:  knapsackLight
number of ops:  33
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                                      !1, !4
          6      > JMPZ                                                     ~7, ->9
          7    >   QM_ASSIGN                                        ~8      !0
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~8      0
         10    >   ASSIGN_DIM                                               !5, 0
         11        OP_DATA                                                  ~8
    5    12        IS_SMALLER_OR_EQUAL                                      !3, !4
         13      > JMPZ                                                     ~10, ->16
         14    >   QM_ASSIGN                                        ~11     !2
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~11     0
         17    >   ASSIGN_DIM                                               !5, 1
         18        OP_DATA                                                  ~11
    6    19        ADD                                              ~13     !1, !3
         20        IS_SMALLER_OR_EQUAL                                      ~13, !4
         21      > JMPZ                                                     ~14, ->25
         22    >   ADD                                              ~15     !0, !2
         23        QM_ASSIGN                                        ~16     ~15
         24      > JMP                                                      ->26
         25    >   QM_ASSIGN                                        ~16     0
         26    >   ASSIGN_DIM                                               !5, 2
         27        OP_DATA                                                  ~16
    7    28        INIT_FCALL                                               'max'
         29        SEND_VAR                                                 !5
         30        DO_ICALL                                         $17     
         31      > RETURN                                                   $17
    8    32*     > RETURN                                                   null

End of function knapsacklight

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.88 ms | 1017 KiB | 17 Q