3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1234567'; $array = ['1', '12', '123', '1234', '456', '56', '7', '3456', '234567']; function get_best_prefix($input, $array){ $best = ''; $sizeBest = 0; foreach ($array as $data) { if (strpos($input, $data) === 0) { $current = strlen($data); if($sizeBest < $current){ $sizeBest = $current; $best = $data; } } } return $best; } echo get_best_prefix($input, $array);
Output for git.master, git.master_jit, rfc.property-hooks
1234

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