$this->get_array($user['uid'],1); function get_array($user_id,$top=0){ $sql = 'SELECT * FROM ' . tablename('weixinmao_house_userinfo').'where pid=:pid'; $params = array(':pid' => $user_id); $rows = pdo_fetchall($sql, $params); foreach ($rows as $key=>$value) { $r = $this->get_array(value $ [ 'uid']); // call the function, passing parameters, to research the lower $ arr [0] [ 'Children'] [ $ Key ] [ 'uid'] = $ value [ 'uid']; / / combination array $ ARR [0] [ 'Children'] [ $ Key ] [ 'wechaname'] = $ value [ 'wechaname']; // composition array IF ( is_array ( $ R & lt )) { $ ARR [0] [ 'Children'] [ $ Key ] [ 'Children'] = $ R & lt [0] [ 'Children' ]; } } return $ ARR ; }