开发者

Convert basic array to PHP array

I have an array that I pull that开发者_StackOverflow社区 looks like this:

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

How do I go about taking that "string" and converting it to a PHP array which I can then manipulate.


This looks like JSON, so you can use json_decode:

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


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

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

print_r($matches);


With exact that code...

$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);


PHP explode is built just for this.

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜