我想将以下字符串分解为10个元素
$str = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o";
进入数组$ arr.Tried with
$arr = explode(",", $str,10);
结果为
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => g
[7] => h
[8] => i
[9] => j,k,l,m,n,o
)
不希望$arr[9]=j,k,l,m,n,o
成为$arr[9]=j
。
答案 0 :(得分:7)
你走了:
$str = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o";
$arr = explode(",", $str);
$output = array_slice($arr, 0, 10); // returns a to j