如何将数组的字符串表示形式转换为实际的php数组

时间:2013-08-06 12:17:55

标签: php

以下是一个例子:

$array = "[[51.228697283276,0.45897198252166],[51.228697283276,0.59374016480853],[51.312903819352,0.59374016480853],[51.312903819352,0.45897198252166]]";

2 个答案:

答案 0 :(得分:5)

看起来像JSON。您可以使用json_decode()对其进行解码:

json_decode($array);

答案 1 :(得分:1)

使用此代码将此字符串设为数组

    <?php 
$string ="[[51.228697283276,0.45897198252166],[51.228697283276,0.59374016480853],[51.312903819352,0.59374016480853],[51.312903819352,0.45897198252166]]";
$array = explode(',',$string);
for($i=0;$i<count($array);$i++){
    $array[$i] = trim($array[$i],'[[');
    $array[$i] = trim($array[$i],']]');
}
echo '<pre>'; print_r($array); ?>