BigBug
BigBug

Reputation: 6290

PHP JSON format object

PHP Noob here...

if i have JSON format: {"0":"0x1001C","1":"0"}
but what i really want is is: {"0x1001C","0"}

how do i attain this?

esentially, i have an array which contains keys and values. i'm removing the keys (as this is a requrement) and the final array must be in object format (in other words, JSON has to return something with {} rather than [] )

Any ideas?

Thanks in advance

Upvotes: 0

Views: 109

Answers (1)

Marc B
Marc B

Reputation: 360702

 echo json_encode(array('0x1001c', '0'), JSON_FORCE_OBJECT);
                                         ^^^^^^^^^^^^^^^^^

as per the docs: http://php.net/json_encode

Upvotes: 2

Related Questions