How do I `json_encode()` keys from PHP array?

前端 未结 4 1668
鱼传尺愫
鱼传尺愫 2020-12-03 10:59

I have an array which prints like this

Array ( [0] => 1691864 [1] => 7944458 [2] => 9274078 [3] => 1062072 [4] => 8625335 [5] => 8255371 [6         


        
4条回答
  •  伪装坚强ぢ
    2020-12-03 12:00

    Use this instead:

    json_encode((object)$temp)
    

    This converts the array into object, which when JSON-encoded, will display the keys.

    If you are storing a sequence of data, not a mapping from number to another number, you really should use array.

提交回复
热议问题