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', array_fill(0, sizeof($words), ' '), $words ); } var_export(splitStrByWords($string));

preferences:
23.15 ms | 408 KiB | 5 Q