用双引号给出数组值 PHP

giving array values with double quotes PHP

我在 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,"longitude":107.6123014,"latitude":-6.897495399999999,"name":"Kaos Oleh Oleh Khas Bandung & Kaos Otomotif"}]

如何在纬度和经度上添加双引号,如下所示:

[{"id":18,"longitude":"107.6123014","latitude":"-6.897495399999999","name":"Kaos Oleh Oleh Khas Bandung & Kaos Otomotif"}]

我试过用这段代码爆炸

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

但它给了我警告:warning explode() expects parameter 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);