Php 在laravel html中连接数组
我正在更新一个旧的Laravel应用程序和PHP,我遇到了应用程序使用的一个部分的问题。我猜这是因为“+”从PHP5.x->7.3改变了。有没有更干净、更好的方法来写这个 以下是它在Laravel 5.0.38/PHP 5.5中的工作方式: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
{!! 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) !!}