I am returning json response to api, using json_encode() method.
I have array which is where a key users can have multiple user or no user i.e empty array,and key course is either empty or can have single object as below
{
"success": true,
"code": 200,
"message": "",
"result": {
"users": [],
"course": []
}
}
if it has data the response is like this
{
"success": true,
"code": 200,
"message": "",
"result": {
"users": [
{
"name": "Vishal",
"Age": 25
},
{
"name": "Akshay",
"Age": 29
}
],
"course": {
"name": "xyz"
}
}
}
but what i want is users should be array in both cases and course should return as object in both cases. is it possible.??