使用双引号PHP给出数组值

使用双引号PHP给出数组值,php,arrays,json,explode,Php,Arrays,Json,Explode,我用php编写了这个json数组代码 $url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-6.893238,107.604273&radius=100&type=point_of_interest&keyword=oleh-oleh&key=mykey"; $data = file_get_contents($url); $json =

我用php编写了这个json数组代码


$url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-6.893238,107.604273&radius=100&type=point_of_interest&keyword=oleh-oleh&key=mykey";

$data = file_get_contents($url);
$json = json_decode($data);

$i = 0;
$results = array_map(function($result) use (&$i) {
    return array ("id" => ++$i , "longitude" => $result->geometry->location->lng, "latitude" => $result->geometry->location->lat, "description" => $result->vicinity, "name" => $result->name);
}, $json->results);

$results = explode('","', $results);

echo json_encode($results);
?>
这为我提供了如下数组值:

[{“id”:18,“经度”:107.6123014,“纬度”:-6.89749539999999,“名称”:“高奥列赫·高奥列赫·哈斯·万隆和高奥托托托蒂夫”}]

如何在lat和long上添加双引号,如下所示:

[{“id”:18,“经度”:“107.6123014”,“纬度”:“-6.89749539999999”,“名称”:“高奥列赫-高奥列赫-万隆和高奥托托蒂夫”}]

我试着用这个代码爆炸

$results=分解(“,”,$results)

但它给了我警告:warning explode()需要参数2

提前感谢您的帮助

将角色转换为字符串

$results = array_map(function($result) use (&$i) {
    return array (
               "id" => ++$i , 
               "longitude" => (string) $result->geometry->location->lng, 
               "latitude" => (string) $result->geometry->location->lat,
               "description" => $result->vicinity, 
               "name" => $result->name
               );
}, $json->results);

为什么需要引号?将值强制转换为字符串数据类型,就在您将它们添加到数组的起始位置。@u\u mulder这是我现在使用的工具所必需的。我认为您不需要强制转换为字符串,您的工具可以很好地处理数值。@u\u mulder我试着运行这个程序,遗憾的是,它没有显示数据非常感谢,它可以工作,或者您可以将报价与
'“+value+'”