I have the following function in PHP, I am trying to get array in a specific format mentioned below but to no success, I am selecting a specific column in the mysql table than contains a json value like
{
"lat": "-0.008668899503063161",
"lng": "0.0025903204871857714"
}
This is the function
function test()
{
$pdo = new PDO ("mysql:host=localhost;dbname=dbname","user", "secret");
$statement=$pdo->prepare("SELECT test FROM merchants WHERE user_id = 1");
$statement->execute();
$data = array();
while( $row = $statement->fetch(PDO::FETCH_ASSOC) )
{
$data[] = json_decode( $row['test'] );
}
return $data ;
}
I am expecting the following result
['lat' => -0.008668899503063161,'lng' => 0.0025903204871857714,]
But this is what I keep getting
[{"lat":"-0.008668899503063161","lng":"0.0025903204871857714"}]