将基本数组转换为PHP数组

时间:2011-06-01 20:16:29

标签: php arrays

我有一个我拉的数组,如下所示:

[157966745,275000353,43192565,305328212] ...

如何获取该“字符串”并将其转换为我可以操作的PHP数组。

5 个答案:

答案 0 :(得分:10)

这看起来像JSON,因此您可以使用json_decode

$str = "[157966745,275000353,43192565,305328212]";
$data = json_decode($str);

答案 1 :(得分:2)

准确的代码......

$string='[157966745,275000353,43192565,305328212]';
$newString=str_replace(array('[', ']'), '', $string); // remove the brackets
$createArray=explode(',', $newString); // explode the commas to create an array

print_r($createArray);

答案 2 :(得分:2)

$s = "[157966745,275000353,43192565,305328212]";

$matches;
preg_match_all("/\d+/", $s, $matches);

print_r($matches);

答案 3 :(得分:0)

PHP explode就是为此而构建的。

$result = explode(',', $input)

答案 4 :(得分:0)

preg_replace('/([\[|\]])/','',$strarr);
$new_arr=explode(','$strarr);