2014-01-09 214 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分析器错误。