I have 2 function in a Class, one is a recursive function.
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);
}
I pass a simple array and parent is null at start:
$o = self::loopOnLevels($categoriesTransformed, 0);
My array looks like: http://screencloud.net/v/10sq ....
Why I get 502 Bad Gateway. Maybe infinite loop? But why?