2016-10-25 3 views
3

사용 후 배열 밀어 내 쿼리 내가 원하는 나에게 적절한 결과를 제공PHP : Laravel - 여기 웅변 뽑은 방법

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

,

입니다하지만 난 쿼리를 실행 한 후 나는 하나 이상의 키를 = > 값 쌍을 사용하여 결과 배열을 푸시합니다.

현재 결과를 인쇄하는 경우 다음과 같습니다.

Illuminate\Support\Collection Object 
(
    [items:protected] => Array 
     (
      [[email protected]*****.com] => Punit Gajjar 
      [[email protected]*****.com] => Milan Gajjar 
      [[email protected]*****.com] => Pritesh Modi 
      [[email protected]*****.com] => Pratik Modi 
      [[email protected]*****.com] => Jyotiranjan J.. 
     ) 

) 

비트 만약 내가 키가 => valye 쌍이 작동하지 않습니다이 배열에 밀어보십시오.

array_push(array("All"=>"All"),$RecipientList); 

당신은 Illuminate\Support\Collection 객체가 아닌 배열을

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

    ) 

답변

5

이있다.

이 작동하지 않는 경우,이 당신을 도울 것입니다

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

희망 코드 아래 노력이

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

보십시오.

1

같은 출력 뭔가 필요합니다. 당신은

$RecipientList->push(["All"=>"All"]); 

UPD 작업을 수행 할 수 있습니다 : $ RecipientList이 컬렉션이 아닌 배열이기 때문이다 prepend 방법

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

아니 .. 내 결과가'이다를 분명히 \ 지원 \ 컬렉션 개체 ( [항목 : 보호] => 배열 ( [[email protected]*****.com] => 대한 Punit Gajjar [밀라노 @ * ****. com] => Milan Gajjar [[email protected]*****.com] => Pritesh Modi [[email protected]*****.com] => Pratik Modi [jyoti @ ***] **. com] => Jyotiranjan J .. [0] => 배열 ( [전체] => 모든 ) ) )'솔루션 사용 후. –

+1

@PunitGajjar'prepend' 메소드는 어떻습니까? '$ RecipientList-> prepend ('All', 'All'); ' – aleksejjj

+0

완벽한 .... !!!!!!!!!! –