php精美评论源码,php⽆限级评论嵌套实例介绍-PHP源码/**
* 按ID条件从评论数组中递归查
*
*/
function getCommentsFromAryById($commtAry, $id)
{
if ( !is_array($commtAry) ) return FALSE;
foreach($commtAry as $key=>$value) {
if ( $value['id'] == $id ) return $value;
if ( isset($value['children']) && is_array($children) ) $this->getCommentsFormAryById($value['children'], $id);
}
}
/**
* 追加 ⼦评论 到 主评论 中,并形成children⼦项
*
* @param array $commtAry 原评论数据引⽤
* @param int $parentId 主评论ID
* @param array $childrenAry ⼦评论的值
*/
function addChildenToCommentsAry($commtAry, $parentId, $childrenAry)
{
if ( !is_array($commtAry) ) return FALSE;
foreach($commtAry as $key=>$value) {
php好看主页源码if ( $value['id'] == $parentId ) {
$commtAry[$key]['children'][] = $childrenAry;
return TRUE;
}
if ( isset($value['children']) ) $this->addChildenToCommentsAry($commtAry[$key]['children'], $parentId, $childrenAry);
}
}
$result = $this->BBDM->select($table, $column, $condition, 0, 1000);
/* 开始进⾏嵌套评论结构重组 */
array_shift($result);
$count = count($result);
$i = 0;
while( $i
if ( '0' != $result[$i]['parentId'] ) {
$this->addChildenToCommentsAry($result, $result[$i]['parentId'], $result[$i]); unset($result[$i]);
}
$i++;
}
$result = array_values($result);
/* 重组结束 */