<?php
'id' => '1',
'name' => 'Имя раздела 1',
'parentid' => '0'
),
'id' => '2',
'name' => 'Имя раздела 2',
'parentid' => '0'
),
'id' => '3',
'name' => 'Имя раздела 3',
'parentid' => '1'
),
'id' => '4',
'name' => 'Имя раздела 4',
'parentid' => '2'
),
'id' => '5',
'name' => 'Имя раздела 5',
'parentid' => '4'
),
'id' => '6',
'name' => 'Имя раздела 6',
'parentid' => '2'
),
);
function form_tree($mess)
{
return false;
}
foreach ($mess as $value) {
$tree[$value['parentid']][] = $value;
}
return $tree;
}
function build_tree($cats, $parent_id)
{
$tree = '<ul>';
foreach ($cats[$parent_id] as $cat) {
$tree .= '<li>' . $cat['name'];
$tree .= build_tree($cats, $cat['id']);
$tree .= '</li>';
}
$tree .= '</ul>';
} else {
return false;
}
return $tree;
}
$tree = form_tree($arr);
echo build_tree($tree, 0);
PD9waHAKJGFyciA9IGFycmF5KAogICAgYXJyYXkoCiAgICAgICAgJ2lkJyA9PiAnMScsCiAgICAgICAgJ25hbWUnID0+ICfQmNC80Y8g0YDQsNC30LTQtdC70LAgMScsCiAgICAgICAgJ3BhcmVudGlkJyA9PiAnMCcKICAgICksCiAgICBhcnJheSgKICAgICAgICAnaWQnID0+ICcyJywKICAgICAgICAnbmFtZScgPT4gJ9CY0LzRjyDRgNCw0LfQtNC10LvQsCAyJywKICAgICAgICAncGFyZW50aWQnID0+ICcwJwogICAgKSwKICAgIGFycmF5KAogICAgICAgICdpZCcgPT4gJzMnLAogICAgICAgICduYW1lJyA9PiAn0JjQvNGPINGA0LDQt9C00LXQu9CwIDMnLAogICAgICAgICdwYXJlbnRpZCcgPT4gJzEnCiAgICApLAogICAgYXJyYXkoCiAgICAgICAgJ2lkJyA9PiAnNCcsCiAgICAgICAgJ25hbWUnID0+ICfQmNC80Y8g0YDQsNC30LTQtdC70LAgNCcsCiAgICAgICAgJ3BhcmVudGlkJyA9PiAnMicKICAgICksCiAgICBhcnJheSgKICAgICAgICAnaWQnID0+ICc1JywKICAgICAgICAnbmFtZScgPT4gJ9CY0LzRjyDRgNCw0LfQtNC10LvQsCA1JywKICAgICAgICAncGFyZW50aWQnID0+ICc0JwogICAgKSwKICAgIGFycmF5KAogICAgICAgICdpZCcgPT4gJzYnLAogICAgICAgICduYW1lJyA9PiAn0JjQvNGPINGA0LDQt9C00LXQu9CwIDYnLAogICAgICAgICdwYXJlbnRpZCcgPT4gJzInCiAgICApLAopOwoKCmZ1bmN0aW9uIGZvcm1fdHJlZSgkbWVzcykKewogICAgaWYgKCFpc19hcnJheSgkbWVzcykpIHsKICAgICAgICByZXR1cm4gZmFsc2U7CiAgICB9CiAgICAkdHJlZSA9IGFycmF5KCk7CiAgICBmb3JlYWNoICgkbWVzcyBhcyAkdmFsdWUpIHsKICAgICAgICAkdHJlZVskdmFsdWVbJ3BhcmVudGlkJ11dW10gPSAkdmFsdWU7CiAgICB9CiAgICByZXR1cm4gJHRyZWU7Cn0KCgpmdW5jdGlvbiBidWlsZF90cmVlKCRjYXRzLCAkcGFyZW50X2lkKQp7CiAgICBpZiAoaXNfYXJyYXkoJGNhdHMpICYmIGlzc2V0KCRjYXRzWyRwYXJlbnRfaWRdKSkgewogICAgICAgICR0cmVlID0gJzx1bD4nOwogICAgICAgIGZvcmVhY2ggKCRjYXRzWyRwYXJlbnRfaWRdIGFzICRjYXQpIHsKICAgICAgICAgICAgJHRyZWUgLj0gJzxsaT4nIC4gJGNhdFsnbmFtZSddOwogICAgICAgICAgICAkdHJlZSAuPSBidWlsZF90cmVlKCRjYXRzLCAkY2F0WydpZCddKTsKICAgICAgICAgICAgJHRyZWUgLj0gJzwvbGk+JzsKICAgICAgICB9CiAgICAgICAgJHRyZWUgLj0gJzwvdWw+JzsKICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgfQogICAgcmV0dXJuICR0cmVlOwp9CgoKJHRyZWUgPSBmb3JtX3RyZWUoJGFycik7CmVjaG8gYnVpbGRfdHJlZSgkdHJlZSwgMCk7