2016-07-06 3 views
0

배열 내부에있는 값을 필터링하려고합니다. 이를 위해 다음 구문을 사용했습니다.배열 내부에 예기치 않은 'if'가 있습니다. Laravel

$selected = array(

     if ($request->annual!=0) { 
      'annual' => $request->annual, 
     } 
     if ($request->registration!=0) { 
      'registration' => $request->registration, 
     } 
     if ($request->monthly!=0) { 
      'monthly' => $request->registration, 
     } 
     if ($request->exam!=0) { 
      'exam' => $request->exam, 
     } 
     if ($request->laboratory!=0) { 
      'laboratory' => $request->laboratory, 
     } 
     if ($request->computer_lab!=0) { 
      'computer_lab' => $request->computer_lab, 
     } 
    ); 

구문 오류가 발생합니다.

syntax error, unexpected 'if' (T_IF), expecting ')' 

여기서 어떤 문제가 발생합니까? 누구든지 나를 도울 수 있습니까?

답변

0

PHP는 허용되지 않습니다. 직접 배열 본문에있는 경우. 다음과 같은

할당 배열 값 :

$selected = array(); 
    if ($request->annual != 0) { 
     $selected['annual'] = $request->annual; 
    } 
    if ($request->registration != 0) { 
     $selected['registration'] = $request->registration; 
    } 
    if ($request->monthly != 0) { 
     $selected['monthly'] = $request->monthly; 
    } 
    if ($request->annual != 0) { 
     $selected['annual'] = $request->annual; 
    } 
관련 문제