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


How to convert this string representation of an array into an actual php array

下面是一个例子:

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

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

json_decode($array);

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

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