我的字符串是
["Alchemy","Alchemy-w","Alchemy-b"]
我怎样才能使它像
Array (
[0] => Alchemy
[1] => Alchemy-w
[2] => Alchemy-b
}
请帮助我,我如何以搁浅的方式获取此输出,否则我必须使用子字符串或任何其他普通的PHP函数来剪切它。
答案 0 :(得分:4)
字符串是有效的json-string。所以你可以使用json_decode:
$json = '["Alchemy","Alchemy-w","Alchemy-b"]';
var_dump(json_decode($json));
答案 1 :(得分:2)
你的字符串是json。这样做:
<?php
$json = '["Alchemy","Alchemy-w","Alchemy-b"]';
$array = json_decode($json, true); //When TRUE, returned objects will be converted into associative arrays.
echo "<pre>"; //to get it displayed nicely
print_r($array);
?>
答案 2 :(得分:0)
您的字符串只是json格式,您可以使用以下mathod。
$resp = '["Alchemy","Alchemy-w","Alchemy-b"]';
print_r(json_decode($resp));