Json values without double quotes

Asked

Viewed 109 times

-1

I have a php/json file in which the numbers coming from an sql query result in double quotes:

"relatorio": [
    "3",
    "1",
    "2"
]

I’d like to leave them without the double quotes on the numbers. I’m using a sql query in php to display the results.

$check = $pdo->prepare("SELECT count(*) as 'total' FROM rating WHERE rt_rating IS NOT NULL group by rt_rating");
$check->execute();
while ( $lista = $check->fetch(\PDO::FETCH_OBJ) )
{
    $out['relatorio'][] = $lista->total;
}

What I would like result to be similar to that:

"relatorio3": [4,2,1]

1 answer

2


Use the constant JSON_NUMERIC_CHECK in the json_encode:

$resultado = json_encode($out, JSON_NUMERIC_CHECK);
  • It worked. Thank you very much :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.