Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.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 在laravel html中连接数组_Php_Laravel - Fatal编程技术网

Php 在laravel html中连接数组

Php 在laravel html中连接数组,php,laravel,Php,Laravel,我正在更新一个旧的Laravel应用程序和PHP,我遇到了应用程序使用的一个部分的问题。我猜这是因为“+”从PHP5.x->7.3改变了。有没有更干净、更好的方法来写这个 以下是它在Laravel 5.0.38/PHP 5.5中的工作方式: {!! Form::select('category', array('ALL'=>'(select)') + $categories, $category) !!} 我做了这个“修复”,它在Laravel 5.1/7.3中起作用: {!! Form

我正在更新一个旧的Laravel应用程序和PHP,我遇到了应用程序使用的一个部分的问题。我猜这是因为“+”从PHP5.x->7.3改变了。有没有更干净、更好的方法来写这个

以下是它在Laravel 5.0.38/PHP 5.5中的工作方式:

{!! Form::select('category', array('ALL'=>'(select)') + $categories, $category) !!}
我做了这个“修复”,它在Laravel 5.1/7.3中起作用:

{!! Form::select('category', array_merge(array('ALL'=>'(select)'), json_decode(json_encode($categories), true)), $category) !!}

绝对没有必要通过
json\u encode
json\u decode
运行您的
$categories
。您这样做似乎是为了将
$categories
从集合转换为数组。如果是这种情况,只需对集合调用
all()
,即可获得底层数组:

{!! Form::select('category', array_merge(['ALL'=>'(select)'], $categories->all()), $category) !!}

绝对没有必要通过
json\u encode
json\u decode
运行您的
$categories
。您这样做似乎是为了将
$categories
从集合转换为数组。如果是这种情况,只需对集合调用
all()
,即可获得底层数组:

{!! Form::select('category', array_merge(['ALL'=>'(select)'], $categories->all()), $category) !!}