How can I force PHP's json_encode integer values to be encoded as String?

后端 未结 2 394
青春惊慌失措
青春惊慌失措 2021-01-24 11:47

I\'m using PHP v5.6.

As i read that php json_encode function is automatically converting int to string. But not in my case. Json_encode is still return it to int not str

2条回答
  •  忘掉有多难
    2021-01-24 12:35

    In the link posted by Thomas in comments, one user suggests that you do this:

    $data = json_encode(array_map('strval', $data));
    

    This might not be the most efficient in terms of performace though, since every entry on the array will pass through the strval function.

提交回复
热议问题