I have an array inside a object, I want to add multiple values to the array, but my codes start to seperates them. The response should like this:
{
"requestTime": "1",
"clients": [{
"name": "Peter",
"id": 905
}]
}
But instead of this it looks like this:
{
"requestTime": "1",
"clients": [{
"name": "Peter"
}, {
"id": 905
}]
}
My Code:
$myObj = new stdClass();
$myObj->requestTime = $reqtime;
$myObj->clients[]->id = $id;
$myObj->clients[]->name = $name;
$myJSON = json_encode($myObj);
echo $myJSON;