php语言中,使用 function来声明一个函数
如: 用function 声明一个名称为 get_article_info的函数,函数的参数为 $id
/**
* 获得指定的文章的详细信息
*
* @access private
* @param integer $id
* @return array
*/
function get_article_info($id)
{
/* 获得文章的信息 */
$sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".
"FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
"LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
"WHERE a.is_open = 1 AND a.article_id = '$id' GROUP BY a.article_id";
$row = $GLOBALS['db']->getRow($sql);
if ($row !== false)
{
$row['comment_rank'] = ceil($row['comment_rank']); // 用户评论级别取整
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
/* 作者信息如果为空,则用网站名称替换 */
if (empty($row['author']) || $row['author'] == '_SHOPHELP')
{
$row['author'] = $GLOBALS['_CFG']['shop_name'];
}
}
return $row;
}