我在一个Class中有2个函数,一个是递归函数。
public static function _itemsByParent($categories, $parentId) {
$out = array();
foreach($categories as $category) {
if(empty($category['parent']) && $parentId == 0)
$out[] = $category;
elseif($category['parent'] == $parentId)
$out[] = $category;
}
return (empty($out) ? false : $out);
}
public static function loopOnLevels($input, $parent=0) {
$categories = self::_itemsByParent($input, $parent);
$out = null;
if($categories !== false) {
$i = 0;
$out = '<ul>';
foreach($categories as $category) {
$out .= '<li>'.$category['name_hu'];
$childs = self::loopOnLevels($input, $category['category_id']);
if($childs !== false) {
$out .= $childs;
}
$out .= '</li>';
$i++;
}
$out .= '</ul>';
}
return (empty($out) ? false : $out);
}
我传递一个简单的数组,父在开始时为空:
$o = self::loopOnLevels($categoriesTransformed, 0);
我的数组如下:http://screencloud.net/v/10sq ....
为什么我会收到502 Bad Gateway。 也许无限循环?但为什么呢?