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
Output for git.master, git.master_jit, rfc.property-hooks
10 16 7

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.15 ms | 405 KiB | 5 Q