3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getNearestMatch($number) { $arr = array_values([2, 4,4, 8, 16,16, 23]); sort($arr); $key = 0; while(isset($arr[$key+1]) && $arr[$key] < $number) $key++; if($arr[$key] == $number || !isset($arr[$key-1]) || $arr[$key] - $number < $number - $arr[$key-1]) return $arr[$key]; else return $arr[$key-1]; } //To test it we pass some values to the function foreach([0, 2, 3, 4, 8, 12, 22, 23, 24] as $v) echo getNearestMatch($v) . PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
2 2 2 4 8 8 23 23 23

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:
43.33 ms | 401 KiB | 8 Q