json - PHP - JSON_ENCODE Number converted to string. How to fix it? -


i have following variable coordinates google maps:

$coordinates = '(22.2819939, 114.15444100000002)'; 

so separate them did following:

$coor = explode(',',str_replace(array('(',')'),'',$coordinates)); 

now need send coordinates api in following format:

$message = array("location"=>array($coor[1],$coor[0])); 

i must send in json encode array getting coordinates strings , not number:

$tosend = json_encode($message); result-> {"location":["114.15444100000002","22.2819939"]} 

how can avoid json take coordinates string , take them number instead?

i need result:

{"location":[114.15444100000002,22.2819939]} 

you'll need convert them string float. map array float conversion

$coor = array_map('floatval', $coor);