Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用maatwebsite在laravel中导出带有动态数组的excel_Php_Laravel 5_Maatwebsite Excel - Fatal编程技术网

Php 使用maatwebsite在laravel中导出带有动态数组的excel

Php 使用maatwebsite在laravel中导出带有动态数组的excel,php,laravel-5,maatwebsite-excel,Php,Laravel 5,Maatwebsite Excel,我想在Laravel 5.7版中导出Excel。我使用的是Maatwebsite Laravel Excel 3.1版软件包。我有一系列这样的个人信息: $persons = { "person 1": [ { "answer1": "shokouh" }, { "answer2": "dareshiri" },

我想在Laravel 5.7版中导出Excel。我使用的是Maatwebsite Laravel Excel 3.1版软件包。我有一系列这样的个人信息:

 $persons = {
        "person 1": [
            {
                "answer1": "shokouh"
            },
            {
                "answer2": "dareshiri"
            },
            {
                "answerN": "answer N"
            }
        ],
...
        "person M ": [
            {
                "answer1": "sarah"
            },
            {
                "answer2": "smith"
            },
            {
                "answerN": "answer N"
            }
        ]
    }
我想将其导出到下面的excel中:

Person 1    Answer 1    Answer 2    …   Answer N
Person M    Answer M2   Answer M2   …   Answer MN
这是我在控制器中的导出功能:

public function export(Request $request, Tournament $tournament) {

    ... 

    $persons;

    return Excel::download(new ParticipantExport($persons), 'personInformation.xlsx');
}
这是我在app\Export\participanexport中的participanexport:

class participantExport implements FromArray
{
    protected $invoices;

    public function __construct(array $invoices)
    {
        $this->invoices = $invoices;
    }

    public function array(): array
    {
        return $this->invoices;
    }
}

任何人都能帮我吗?

我解决了这个问题如下:

在Controller.php中:

$rows = array();

        foreach ($persons as $slug => $person) {
            $row = array();
            array_push($row, $slug);
            foreach ($person as $key => $value) {

                array_push($row, $persons[$slug][$key]['answer']);

            }
            array_push($rows, $row);
        }

        $coll = new participantExport([$rows]);


        return Excel::download($coll, 'participant-information.xlsx');