3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10'; $times = 4; [$string1, $string2] = preg_split("/(?:[^,]+\K,? ?){0,$times}/", $str, 2); var_dump($string1, $string2);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
string(26) "temp1, temp2, temp3, temp4" string(41) "temp5, temp6, temp7, temp8, temp9, temp10"

preferences:
60.52 ms | 402 KiB | 62 Q