I build my Rest Apis on PHP 5.5.9, in which json_encode() was returning numeric values as a string, but now I am setting up same Rest Apis on different server with PHP 5.6 and here json_encode() is returning numeric values as numeric,
But I need the same behavior as PHP 5.5.9, because my client apps are way huge and I have been handling numeric as string value in all client Apps, so currently it is not possible for me to handle numeric as numeric, I need numeric as string, how can I achieve this?
For data
array("id" => 1);
On my original server which is based on 5.5.9, I was getting response like this:
{"id": "1"}
And now on another server which is based on 5.6, I am getting response like this:
{"id": 1}
But I need response in this form on my new server:
{"id": "1"}
Can anyone provide me a suitable solution for this?
EDIT
"I have multi-dimensional arrays and I am fetching data from database. I cannot modify all the Api Code"
Example response:
[
{
"id": 4220,
"user_id": 151,
"truckId": 8,
"truckType": "",
"InsertionDateTime": "2017-05-30 08:25:20",
"flag": 1
},
{
"id": 4221,
"user_id": 151,
"truckId": 8,
"truckType": "",
"InsertionDateTime": "2017-05-30 08:34:28",
"flag": 1
}
]
array("id" => "1");?echo json_encode(array("id" => (string) 1));