I tried transfer $str
to be an array group.
$str = '1,2,3,4,5';
print_r(array($str)); //this get Array ( [0] => 1,2,3,4,5 )
I tried compact
print_r(array(compact($str))); // Array ( [0] => Array ( ) )
but how to make $str
to be
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
You should try to use explode
keyword.
$str = '1,2,3,4,5';
print_r(explode(',', $str));
Should print:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
Try with:
$str = array(1,2,3,4,5);
Otherwise, if you mean that your input is '1,2,3,4,5' then use explode:
$str = explode(',', '1,2,3,4,5');
In both cases the output of print_r($str); is:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
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