Php:Laravel-使用雄辩的Pull方法后的数组推送

Php:Laravel-使用雄辩的Pull方法后的数组推送,php,arrays,laravel,array-push,Php,Arrays,Laravel,Array Push,这是我的问题 $RecipientList = Employees::select(DB::Raw('CONCAT(first_name," ",last_name) as employee_name'),'email')->pluck('employee_name','email'); 这给了我想要的正确结果 但在执行查询之后,我还有1个key=>value对要推入结果数组 如果我打印当前结果,它是这样的 Illuminate\Support\Collection Object (

这是我的问题

$RecipientList = Employees::select(DB::Raw('CONCAT(first_name," ",last_name) as employee_name'),'email')->pluck('employee_name','email');
这给了我想要的正确结果

但在执行查询之后,我还有1个key=>value对要推入结果数组

如果我打印当前结果,它是这样的

Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [punit@*****.com] => Punit Gajjar
            [milan@*****.com] => Milan Gajjar
            [pritesh@*****.com] => Pritesh Modi
            [pratik@*****.com] => Pratik Modi
            [jyoti@*****.com] => Jyotiranjan J..
        )

)
位如果我尝试将我的Key=>valye对推入这个数组,它将不起作用

array_push(array("All"=>"All"),$RecipientList);
需要像这样的输出吗

Illuminate\Support\Collection Object
    (
        [items:protected] => Array
            (
                [All] => All
                [milan@*****.com] => Milan Gajjar
                [milan@*****.com] => Milan Gajjar
                [pritesh@*****.com] => Pritesh Modi
                [pratik@*****.com] => Pratik Modi
                [jyoti@*****.com] => Jyotiranjan J..
            )

    )

您有
照明\Support\Collection
对象而不是数组。你能行

$RecipientList->push(["All"=>"All"]);
UPD:有
prepend
方法

$RecipientList->prepend('All', 'All');

这是因为$RecipientList是集合而不是数组

试试这个

RecipientList = Employees::select(DB::Raw('CONCAT(first_name," ",last_name) as employee_name'),'email')->pluck('employee_name','email')->toArray();
如果这不起作用,请尝试下面的代码

RecipientList = Employees::select(DB::Raw('CONCAT(first_name," ",last_name) as employee_name'),'email')->get()->pluck('employee_name','email')->toArray();

希望这能对你有所帮助。

不。。我的结果是
illumb\Support\Collection Object([items:protected]=>Array([punit@******.com]=>punit Gajjar[milan@*********.com]=>milan Gajjar[pritesh@******.com]=>pritesh Modi[pratik@******.com]=>pratik Modi[jyoti@******.com]=>Jyotiranjan J..[0]=>Array([All]=>All))
使用您的解决方案后。@PunitGajjar使用
prepend
方法怎么样<代码>$RecipientList->prepend('All','All')