When $ user_list is 0, it will be called again. If $ user_list is 0 again, $ result {code...} will be returned, which may be easier to see:
When$user_listWhen the value is 0, it will be called again,$user_listIf it is 0 again, it will return$result
Function count_user_order ($ user_list_str, $ limit = 4, $ times = 1) {static $ result = array ('users _ count' => array (), 'order _ number' => array (), 'order _ amount' => array (); $ SQL = 'select user_id FROM '. $ GLOBALS ['ecs']-> table ('users '). "WHERE parent_id IN (% s)"; // collects $ user_list = $ GLOBALS ['db']-> getCol (sprintf ($ SQL, $ user_list_str )); $ SQL _order = 'select SUM (order_amount) order_amount, COUNT (*) order_num Ber FROM '. $ GLOBALS ['ecs']-> table ('order _ info '). "WHERE pay_status = 2 AND user_id IN (% s)"; // count the order quantity AND amount list ($ result ['order _ amount'] [], $ result ['order _ number'] []) = $ GLOBALS ['db']-> getRow (sprintf ($ SQL _order, $ user_list_str )); $ result ['users _ count'] [] = count ($ user_list); if ((! $ Limit | $ times <$ limit) & count ($ user_list) {$ user_list_str = implode (',', $ user_list); count_user_order ($ user_list_str, $ limit, + $ times);} return $ result ;}
Perhaps images are easier to see:
Reply content:
When$user_listWhen the value is 0, it will be called again,$user_listIf it is 0 again, it will return$result
Function count_user_order ($ user_list_str, $ limit = 4, $ times = 1) {static $ result = array ('users _ count' => array (), 'order _ number' => array (), 'order _ amount' => array (); $ SQL = 'select user_id FROM '. $ GLOBALS ['ecs']-> table ('users '). "WHERE parent_id IN (% s)"; // collects $ user_list = $ GLOBALS ['db']-> getCol (sprintf ($ SQL, $ user_list_str )); $ SQL _order = 'select SUM (order_amount) order_amount, COUNT (*) order_num Ber FROM '. $ GLOBALS ['ecs']-> table ('order _ info '). "WHERE pay_status = 2 AND user_id IN (% s)"; // count the order quantity AND amount list ($ result ['order _ amount'] [], $ result ['order _ number'] []) = $ GLOBALS ['db']-> getRow (sprintf ($ SQL _order, $ user_list_str )); $ result ['users _ count'] [] = count ($ user_list); if ((! $ Limit | $ times <$ limit) & count ($ user_list) {$ user_list_str = implode (',', $ user_list); count_user_order ($ user_list_str, $ limit, + $ times);} return $ result ;}
Perhaps images are easier to see:
If you just scan it, there should be no exit, that is, there is no condition for stopping recursion.
You should also write a function to count the customer and the order quantity and amount.