I have read a question answer at
PHP Array to json, how to get rid of some double quotes?
I have same issue but my code is little different so I unable to ride of rid of some double quotes.
My code :
$features = array();
$geojson = array(
'type' => 'FeatureCollection',
'features' => $features
);
while($row = mysqli_fetch_assoc($result)) {
$type = $row['type'];
if($type == 'Point')
{
//$output = ;
$feature = array(
'type' => 'Feature',
'properties' => array(
'score' => "",
'fid' => ""
//Other fields here, end without a comma
),
'geometry' => array(
'type' => $type,
'coordinates' => array($row['lat'], $row['lng'])
)
);
}
else {
//$output = '['.$row['more_info'].']';
$feature = array(
'type' => 'Feature',
'properties' => array(
'score' => "",
'fid' => ""
//Other fields here, end without a comma
),
'geometry' => array(
'type' => $type,
'coordinates' => array('['.$row['more_info'].']')
)
);
}
array_push($geojson['features'], $feature);
};
mysqli_close($conn);
echo $newgeojson = json_encode($geojson, JSON_NUMERIC_CHECK);
array Output before convert to json (json_encode):
Array
(
[type] => FeatureCollection
[features] => Array
(
[0] => Array
(
[type] => Feature
[properties] => Array
(
[score] =>
[fid] =>
)
[geometry] => Array
(
[type] => Point
[coordinates] => Array
(
[0] => 88.388786315918
[1] => 22.551879205144
)
)
)
[1] => Array
(
[type] => Feature
[properties] => Array
(
[score] =>
[fid] =>
)
[geometry] => Array
(
[type] => Polygon
[coordinates] => Array
(
[0] => [[88.41796875, 22.568048815726],[88.41796875, 22.572804222704],[88.41796875, 22.577876475976],[88.428955078125, 22.578114233267],[88.428955078125, 22.573121244003],[88.428611755371, 22.568048815726],[88.41796875, 22.568048815726]]
)
)
)
)
)
Output I am getting after json_encode
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"score":"","fid":""},"geometry":{"type":"Point","coordinates":[88.388786315918,22.551879205144]}},{"type":"Feature","properties":{"score":"","fid":""},"geometry":{"type":"Polygon","coordinates":["[[88.41796875, 22.568048815726],[88.41796875, 22.572804222704],[88.41796875, 22.577876475976],[88.428955078125, 22.578114233267],[88.428955078125, 22.573121244003],[88.428611755371, 22.568048815726],[88.41796875, 22.568048815726]]"]}}]}
As you can see the coordinates coming with " ".
"[[88.41796875, 22.568048815726],[88.41796875, 22.572804222704],[88.41796875, 22.577876475976],[88.428955078125, 22.578114233267],[88.428955078125, 22.573121244003],[88.428611755371, 22.568048815726],[88.41796875, 22.568048815726]]"
I do not want that double quote start and end of multi coordinates.
Please guide / suggest me how can I ride of those double quote.