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));
Output for git.master, git.master_jit, rfc.property-hooks
int(10) int(10)

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:
176.43 ms | 405 KiB | 5 Q