3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input = '1234567'; $array = ['1', '12', '123', '1234', '456', '56', '7', '3456', '234567']; function get_best_prefix($input, $array, $limit = -1, &$count){ $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);
based on XjZ9Q
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function get_best_prefix(), 2 passed in /in/p5ai7 on line 26 and exactly 4 expected in /in/p5ai7:7 Stack trace: #0 /in/p5ai7(26): get_best_prefix('1234567', Array) #1 {main} thrown in /in/p5ai7 on line 7
Process exited with code 255.
Output for 5.4.0 - 7.0.20
Warning: Missing argument 4 for get_best_prefix(), called in /in/p5ai7 on line 26 and defined in /in/p5ai7 on line 7 1234
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/p5ai7 on line 4
Process exited with code 255.