将数组的集合转换为对象

I'm currently pushing array data. How can I return the object like this:

"data": [
    {
        "apartment": {
            {
                "id": xxx,
                "show": "xxx,
            },
            {
                "id": xxx,
                "show": "xxx",
            },

and not like this:

 "data": [
    {
        "apartment": {
            "0": {
                "id": xxx,
                "show": "xxx,
            },
            "1" : {
                "id": xxx,
                "show": "xxx",
            },

This code:

data[] = array("id" => 1)

Will add a named array to the data array.

data = [ {"id" => 1} ]

If you want data to be a named array, you should add your "id" => 1 like this:

data[1] = {"id" => 1}

This will result in:

data = { 1 => {"id" => 1} }