Php Laravel 5.1:命令错误[错误异常]非法偏移类型

Php Laravel 5.1:命令错误[错误异常]非法偏移类型,php,arrays,multidimensional-array,foreach,laravel-5.1,Php,Arrays,Multidimensional Array,Foreach,Laravel 5.1,我正在为laravel 5.1编写一个自定义命令,当我运行它时,它只是说: [错误异常]偏移量类型非法 这是我的密码: namespace App\Console\Commands; use Illuminate\Console\Command; class InsertDefaultData extends Command { /** * The name and signature of the console command. * * @var s

我正在为laravel 5.1编写一个自定义命令,当我运行它时,它只是说: [错误异常]偏移量类型非法 这是我的密码:
namespace App\Console\Commands;

use Illuminate\Console\Command;

class InsertDefaultData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'data:default';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Used for inserting the default data';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $data = array(
                [0] => array(
                        ['name'] => 'Edit',
                        ['slug'] => 'edit',
                        ['view'] => 'admin.edit'
                    ),
                [1] => array(
                        ['name'] => 'Statistics',
                        ['slug'] => 'statistics',
                        ['view'] => 'admin.statistics'
                    ),
                [2] => array(
                        ['name'] => 'Settings',
                        ['slug'] => 'settings',
                        ['view'] => 'admin.settings'
                    ),
                [3] => array(
                        ['name'] => 'Media',
                        ['slug'] => 'media',
                        ['view'] => 'admin.media'
                    )
            );

        foreach ($data as $key => $data) {
            DB::insert('INSERT INTO dashboard_sites (id, name, slug, view) VALUES (NULL, ?, ?, ?)', [$data[$key]['name'], $data[$key]['slug'], $data[$key]['view']]);
        }

        $data = array(
                [0] => array(
                        ['name'] => 'Edit',
                        ['text'] => 'Edit',
                        ['link'] => '/admin/dashboard/edit',
                        ['order'] => 1
                    ),
                [1] => array(
                        ['name'] => 'Statistics',
                        ['text'] => 'Statistics',
                        ['link'] => '/admin/dashboard/statistics',
                        ['order'] => 3
                    ),
                [2] => array(
                        ['name'] => 'Media',
                        ['text'] => 'Media',
                        ['link'] => '/admin/dashboard/media',
                        ['order'] => 2
                    ),
                [3] => array(
                        ['name'] => 'Settings',
                        ['text'] => 'Settings',
                        ['link'] => '/admin/dashboard/settings',
                        ['order'] => 4
                    )
            );

        foreach ($data as $key => $data) {
            DB::insert('INSERT INTO dashboard_menu (id, name, text, link, order) VALUES (NULL, ?, ?, ?, ?)', [$data[$key]['name'], $data[$key]['text'], $data[$key]['link'], $data[$key]['order']]);
        }

    }
}
我不想让它运行多维数组,然后将数据插入到我的数据库中,但它只在运行时返回错误。
您能帮助我正确运行它吗?

看起来您正在将数组键包装在[]中,php在数组中解释[]。不能将数组用作偏移/数组键

只需使用:

0 => array( 'name' => 'Edit',...
1 => array(...
你应该表现得很好

不幸的是,PHP不允许使用数组作为数组键,正如@Zoe Blair所说的那样。实际上,你所需要做的就是移除钥匙周围的支架