使用php创建动态树

时间:2017-07-22 10:07:54

标签: php mysql

我有一个使用php mysql的动态树视图代码。

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

我只是想...喜欢。我有一个变量

$top = '1234';

现在如何将此功能放入

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

如果我把$ top放在这个函数中,那么我会遇到致命的错误。请帮帮我

2 个答案:

答案 0 :(得分:1)

您无法将默认值指定为参数的另一个变量。您可以使用常量

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

答案 1 :(得分:0)

如果您确实需要默认动态值:

$top = '1234' ;

// Some code

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

但是如果值是常数,请看看B Desai的答案。

相关问题