public static function getLeafIds($id) { $ret = []; $current = Channel::findOne(['id' => $id]); if ($current['is_leaf']) { $ret[] = $id; return $ret; } $children = Channel::findAll(['parent_id' => $id]); if (count($children) > 0) { foreach ($children as $child) { $temp = Channel::getLeafIds($child['id']); $ret = array_merge($ret, $temp); } } return $ret; }