3v4l.org

run code in 300+ PHP versions simultaneously
<?php function binary_search(array $array, integer $target) { $max = count($array) - 2; $min = 0; while ($max - $min > 1) { if ($target < $array[($max - $min) / 2]) { $max = ($max + $min) / 2; } else { $min = ($max + $min) / 2; } } return $result = $array[$max + $min / 2] === $target ? true : false; } echo('Searching for 6 in 1,2,3,4,5,6'); $array = [1,2,3,4,5,6]; $target = 6; $result = binary_search($array, $target); echo($result); echo('Searching for 3 in 1,2,3,4,5'); $array = [1,2,3,4,5]; $target = 3; $result = binary_search($array, $target); echo($result);
Output for git.master_jit, git.master, rfc.property-hooks
Warning: "integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning in /in/fa0VD on line 3 Searching for 6 in 1,2,3,4,5,6 Fatal error: Uncaught TypeError: binary_search(): Argument #2 ($target) must be of type integer, int given, called in /in/fa0VD on line 20 and defined in /in/fa0VD:3 Stack trace: #0 /in/fa0VD(20): binary_search(Array, 6) #1 {main} thrown in /in/fa0VD on line 3
Process exited with code 255.

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