2017-07-22 92 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 
}