lundi 20 avril 2020

How to put a retuned array into another returned array?

I have two files which return two arrays.

First:

<?php
return [
    "cats" => [
        [
            'id' => 1,
            "title" => 'qwer',
        ],
        [
            'id' => 2,
            "title" => 'asdf',
        ]
    ]
]

Second:

<?php
return [
    "fixtures" => [
            include "file1.php",
            "dogs" => [
                [
                    'id' => 1,
                    "title" => 'qwer',
                ],
            ],
            "pigs" => [
                [
                    'id' => 1,
                    "title" => 'qwer',
                ],
            ],
        ]
]

The array from first file must be putted into array in second file. But if I do this by include it puts file1.php with outside brackets and I get this:

<?php
return [
    "fixtures" => [
            [
                 "cats" => [
                         [
                             'id' => 1,
                             "title" => 'qwer',
                         ],
                         [
                             'id' => 2,
                             "title" => 'asdf',
                         ]
                  ]
            ],
            "dogs" => [
                [
                    'id' => 1,
                    "title" => 'qwer',
                ],
            ],
            "pigs" => [
                [
                    'id' => 1,
                    "title" => 'qwer',
                ],
            ],
        ]
]

How can I put array from file1 without these outside brackets?

Aucun commentaire:

Enregistrer un commentaire