php - Remove quotes from json_encoded ints prior to 5.3.3 -


when using json_encode, annoyingly automatically coverts int keys strings. example, if have array:

$a = array();  $a[12] = 15; echo json_encode($a); {"12":15} //notice quotes around 12 

after searching so, solution use

json_encode($array,json_numeric_check) 

however, available in php > 5.3.3. production server i'm stuck using 5.3.2.

surely there work around?

so problem here mixing approach data structure , json_encode() trying make best guess how interpret array, since in json, there not such concept of non-zero based, numerically indexed array.

if example, had zero-based numeric array continuous number sequence, json_encode() encode a numerically-indexed array of format:

[value1, value2, ...] 

since don't have zero-based array, data structure being interpreted object structure , given string key (the available key type object in json) of format:

{"key", value} 

so seems need make mind trying represent in array. need numerically based array, or need object encoding.


Comments

Popular posts from this blog

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -