2014-01-09 270 views
-1

我有這個僞代碼,我一直在試圖創建正確的PHP語法,並且我得到了絕對的無處不在。我繼續在函數group_job_items上得到一個Parse錯誤。PHP解析語句錯誤if語句

Parse error: syntax error, unexpected '{' on line 17

這裏有什麼問題?任何幫助將不勝感激。

function group_job_items() 
{ 
    $jobs_by_category = array(); 
    foreach ($category_name as $category_id => $name) 
    { 
     foreach ($job_item as $item) 
     { 
      // skip job items that do not match the current category 
      if ($item["category_id"] != $category_id) continue; 

      if (!isset ($jobs_by_category[$name]) 
      { 
       // create a list of jobs for the current category 
       $jobs_by_category[$name] = array(); 
      } 

      // add the current job item to the current category 
      $jobs_by_category[$name][] = $item 
     } 
    } 
} 
+1

計算開合圓括號;你錯過了最後一個。 – Gumbo

回答

1
<?php 

function group_job_items() 
{ 
    $jobs_by_category = array(); 
    foreach ($category_name as $category_id => $name) 
    { 
     foreach ($job_item as $item) 
     { 
      // skip job items that do not match the current category 
      if ($item["category_id"] != $category_id) continue; 

      if (!isset ($jobs_by_category[$name])) 
      { 
       // create a list of jobs for the current category 
       $jobs_by_category[$name] = array(); 
      } 

      // add the current job item to the current category 
      $jobs_by_category[$name][] = $item; 
     } 
    } 
} 
?> 
0

更改...

if (!isset ($jobs_by_category[$name]) 
      { 
       // create a list of jobs for the current category 
       $jobs_by_category[$name] = array(); 
      } 

if (!isset ($jobs_by_category[$name])) 
      { 
       // create a list of jobs for the current category 
       $jobs_by_category[$name] = array(); 
      } 
0

有幾個語法提交的代碼中的錯誤。

甲閉括號/托架缺少在此行的末尾:

if (!isset ($jobs_by_category[$name]) 

分號缺少在此行的末尾:

$jobs_by_category[$name][] = $item 

使這些校正應該解決PHP分析器錯誤。