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, $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);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Deprecated: Optional parameter $limit declared before required parameter $count is implicitly treated as a required parameter in /in/p5ai7 on line 7 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 8.0.0 - 8.0.30
Deprecated: Required parameter $count follows optional parameter $limit in /in/p5ai7 on line 7 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 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.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

preferences:
176.71 ms | 402 KiB | 245 Q