Reputation: 159
I am trying to return information from a mysql database using php and need to get rid of the "" in the dynamic values. I have tried using real_escape_string and trim but this has not worked.
while($row = mysqli_fetch_assoc($result)) {
$myArray= array(
// array("running"=> 23),
// array("walking"=> 54)
array("running"=>$row['running']),
array("walking"=>$row['walking'])
);
}
echo json_encode($myArray);
As the code currently stands it returns [{"running":"23"},{"walking":"54"}]
However, I need it to return [{"running":23},{"walking":54}]
without the "" characters (It returns this using my commented out static code)
Upvotes: 1
Views: 37
Reputation: 21
You can use the JSON_NUMERIC_CHECK parameter in the json_encode().
echo json_encode($myArray, JSON_NUMERIC_CHECK);
JSON_NUMERIC_CHECK (integer)
Encodes numeric strings as numbers. Available as of PHP 5.3.3.
Upvotes: 1