3v4l.org

run code in 300+ PHP versions simultaneously
<?php function binary_search(array $array, int $target) { $max = count($array) - 1; $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
Searching for 6 in 1,2,3,4,5,6 Deprecated: Implicit conversion from float 2.5 to int loses precision in /in/EXt1H on line 8 Deprecated: Implicit conversion from float 1.25 to int loses precision in /in/EXt1H on line 8 Deprecated: Implicit conversion from float 0.625 to int loses precision in /in/EXt1H on line 8 Deprecated: Implicit conversion from float 7.1875 to int loses precision in /in/EXt1H on line 14 Warning: Undefined array key 7 in /in/EXt1H on line 14 Searching for 3 in 1,2,3,4,5 Deprecated: Implicit conversion from float 5.5 to int loses precision in /in/EXt1H on line 14 Warning: Undefined array key 5 in /in/EXt1H on line 14

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:
63.54 ms | 402 KiB | 8 Q