Last updated on April 21st, 2020 at 02:48 am
PHP CODE–>
foreach($location as $u=> $v)
{
$final_location .= "[".$u.",".$v."],";
}
Sending With Json–>
echo json_encode(array(
"location"=>"$final_location"
));
Result is ->
{"location":"[1407110400000,6641],[1407196800000,1566],[1407283200000,3614],[1407369600000,3654],[1407456000000,2918],[1407715200000,3900],[1407715200000,3900],"}
Desired Result ->
{"location":[1407110400000,6641],[1407196800000,1566],[1407283200000,3614],[1407369600000,3654],[1407456000000,2918],[1407715200000,3900],[1407715200000,3900]}
Following Code Will Give You The Desired Result
foreach($location as $u=> $v)
{
$final_location .= "[".$u.",".$v."],";
}
$final_value = json_encode(array(
"location"=> rtrim($final_location ,',')
));
echo str_replace(']"',']',str_replace('"[',"[",$final_value));