3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "This is my test case for an example"; function splitStrByWords($sentence, $wordCount=2) { $words = array_chunk( explode(' ', $sentence), $wordCount ); return array_map( 'implode', $words, array_fill(0, sizeof($words), ' ') ); } var_export(splitStrByWords($string));
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/RKFkV:10 Stack trace: #0 [internal function]: implode(Array, ' ') #1 /in/RKFkV(10): array_map('implode', Array, Array) #2 /in/RKFkV(16): splitStrByWords('This is my test...') #3 {main} thrown in /in/RKFkV on line 10
Process exited with code 255.
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/RKFkV:13 Stack trace: #0 [internal function]: implode(Array, ' ') #1 /in/RKFkV(13): array_map('implode', Array, Array) #2 /in/RKFkV(16): splitStrByWords('This is my test...') #3 {main} thrown in /in/RKFkV on line 13
Process exited with code 255.

preferences:
93.2 ms | 408 KiB | 5 Q