2016-07-06 8 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; 
    } 
関連する問題