2017-07-22 50 views
0

我有一個使用php mysql的動態樹視圖的代碼。使用php創建動態樹

function fetchCategoryTreeList($parent = '', $user_tree_array = '') 
{ 
    // code here 
} 

我只是想......喜歡。我有一個變量

$top = '1234'; 

現在怎麼把這個功能就像

function fetchCategoryTreeList($parent = $top, $user_tree_array = '') 
{ 
    // code here 
} 

,如果我把$頂部,這個功能的話,我得到了致命的錯誤。請幫我

+0

僅通過添加$ top ='1234'就不會產生致命錯誤;進入功能。我們需要您真實的代碼來查看問題。 –

+1

您不能將默認值設置爲另一個變量。 –

+0

@PierreGranger由於函數參數中的'$ parent = $ top',他得到了錯誤 –

回答

0

如果你真的需要一個默認的動態值:

$top = '1234' ; 

// Some code 

function fetchCategoryTreeList($parent = '', $user_tree_array = '') 
{ 
    global $top ; 
    if ($parent == null || $parent == '') $parent = $top ; 
    // code here 
} 

但是,如果值是恆定看一看在B處德賽答案。

1

你不能將默認值作爲另一個變量分配給參數。您可以使用常數代替

define("TOP", "1234"); 
function fetchCategoryTreeList($parent = TOP, $user_tree_array = '') 
{ 
    // code here 
}