I am using PHP’s PDO to query a MySQL database. It returns numbers and integers as strings, and is messing with my JSON.
Is there a better way of fixing it other than type casting the values row by row?
array(2) {
["name"]=> string(11) "Preliminary"
["sell_price"]=> string(6) "864.00"
}
If you are using php 5.3.3 or higher you can use
JSON_NUMERIC_CHECKas the second argument tojson_encodeto do this.See: https://www.php.net/manual/en/function.json-encode.php