hierarchical data - how to return static variable PHP -


  फ़ंक्शन build_path ($ cid) {static $ fr = array (); $ DB = नया MySQLTable; $ डीबी- & gt; टीबीएलनाम = 'दुकान_कैचर्स'; $ जहां ['cat_id'] ['='] = $ cid; $ Res = $ DB- & gt; चुनें ('cat_id, cat_name, cat_parent', $ जहां); अगर ($ res! == गलत) {$ pid = mysql_fetch_array ($ res); अगर ($ pid ['cat_parent']! == "0") {$ fr [] = $ pid ['cat_id']; build_path ($ पीआईडी ​​[ 'cat_parent']); } और {$ fr [] = $ cid; $ Fr = array_reverse ($ fr); print_r ($ fr); वापसी $ fr; }}} Print_r (build_path (100));  

फ़ंक्शन पर print_r काम क्यों कर रहा है, लेकिन दूसरा प्रिंट_आर्ट नल देता है?

आम तौर पर, कार्य करने के लिए रिकर्सिव फ़ंक्शन के लिए, आपको स्वयं को कॉल करते समय कुछ वापस करने की आवश्यकता होती है।

इसे ब्लॉक करने के लिए अपने पहले नेस्टेड में आज़माएं:

  return build_path ( $ पीआईडी ​​[ 'cat_parent']);  

Comments

Popular posts from this blog

php - Login to icq account to receive messages from contact #12345678 -

windows - Heroku throws SQLITE3 Read only exception -

string - javascript - switch not working -