static function makeParentChildRelationsForTree(&$inArray, &$outArray, $currentParentId = 0) { if (!is_array($inArray)) { return; } if (!is_array($outArray)) { return; } foreach ($inArray as $key => $tuple) { if ($tuple['parent'] == $currentParentId) { $tuple['children'] = array(); TochucHelper::makeParentChildRelationsForTree($inArray, $tuple['children'], $tuple['id']); $outArray[] = $tuple; } } }