簡體   English   中英

使用php創建動態樹

[英]create dynamic tree using php

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

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

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

$top = '1234';

現在如何把這個功能像

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

如果我將$ top放在此函數中,則會出現致命錯誤。 請幫我

您不能將默認值作為另一個變量分配給參數。 您可以改用常量

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

如果您確實需要默認動態值:

$top = '1234' ;

// Some code

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

但是,如果該值恆定,請看一下B Desai的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM