你不需要任何循环
$string = "1.name.2.name,3.name.8.name";
$array = explode(",", $string);
var_dump($array);
输出
array (size=2)
0 => string '1.name.2.name' (length=13)
1 => string '3.name.8.name' (length=13)
如果你想进一步打破它
$array = array_map(function($v){return explode(".", $v); },$array);
var_dump($array);
输出
array (size=2)
0 =>
array (size=4)
0 => string '1' (length=1)
1 => string 'name' (length=4)
2 => string '2' (length=1)
3 => string 'name' (length=4)
1 =>
array (size=4)
0 => string '3' (length=1)
1 => string 'name' (length=4)
2 => string '8' (length=1)
3 => string 'name' (length=4)