I want to explode the following string upto 10 elements
$str = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o";
into array $arr.Tried with
$arr = explode(",", $str,10);
It gives result as
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
)
dont want $arr[9]=j,k,l,m,n,o
should be $arr[9]=j
.
Here you go:
$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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With