<?php
$str = 'temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8, temp9, temp10';
$times = 4;
[$string1, $string2] = preg_split("/(?:[^,]+,? ?){0,$times}\K/", $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(28) "temp1, temp2, temp3, temp4, "
string(41) "temp5, temp6, temp7, temp8, temp9, temp10"
preferences:
65.45 ms | 402 KiB | 62 Q