Level 56
Show some code where you are having this issue. Right now this is very vague.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi :)
when I use API resources it makes a sub-array of object How do I force him to make sub Object of Objects
"sub_object" - should be Object of Objects!
The final result that should be :
{
"object": [
{
"username": "username",
"lastname": "lastname",
"sub_object": {
"object_1": {
"sub_object_name": "something",
"sub_object_status": "wow",
},
"object_2": {
"sub_object_name": "something2",
"sub_object_status": "wow2",
},
}
}
],
}
thanks!
If the sub_object array has non-numeric or non-zero indexed keys; you will get an object. You can force this by mapping over the sub_object array.
Please or to participate in this conversation.