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

后端 未结 2 377
青春惊慌失措
青春惊慌失措 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:24

    json_encode(['code' => 200, 'results' => [id=> strval(1)]]);
    

    With strval() php will return

    The string value of var.

提交回复
热议问题