如何将字符串转换为数组[重复]

This question already has an answer here:

How can i convert string ids

$ids = '8552479333,8552438544,';

to look like an array

["8552479333","8552438544"]

I tryed :

$ids = (explode(",",$ids,-1));

but this gives me :

Array ( [0] => 8552479333 [1] => 8552438544)
</div>

This is a very specific way of formatting. You could miss use the json encoding routines to get the exact result you are looking for:

<?php
$ids = '8552479333,8552438544,';
$string = json_encode(explode(',', $ids, -1));
var_dump($string);

The output obviously is:

string(27) "["8552479333","8552438544"]"
<?php
$ids = '8552479333,8552438544,';
$ids = json_encode(explode(',', $ids, -1));
print_r($ids);
?>