/**
*Converts a one-dimensional array of labels read from a database into a tag tree form
*Depending on the value of eachPARENT_ID,Leaves that change to the corresponding value
*@paramsArray $tagListOne-dimensional array read from the database,Each value of the array containsIdAndparent_id
* int $rootThe parent of the root nodeID string $idDefault isIdColumn NameString $pidDefault isparent_idColumn NameString $childIndex of Branch Point
*@returnArray $treeA label tree for multidimensional arrays
* */
static functionGetdictionarytree ($tagList,$root =0,$id =' ID ',$pid =' ParentID ',$child =' Child ') {
$tagTree =Array ();//Tree
if (Is_array ($tagList)) {
$array =Array ();
foreach ($tagListAs$key =$item) {
$array [$item [$id]] = &$tagList [$key];//Extracts the address of each element in the array in memory
}
foreach$tagListAs$key =$item) {
$parentId =$item [$pid];
If$root = =$PARENTID) {
$tagTree [] = &$tagList [$key];
}else{
IfIsset$array [$PARENTID])) {
$parent = &$array [$PARENTID];//Find the parent directlyIdIn-memory address,Then add child nodes
$parent [' node '] =True;NodeForTrueIndicates that there are child nodes under it,Convenient front desk Display this item can be expanded
$parent [$child [] = &$tagList [$key];
}
}
}
}
Return$tagTree;
}
/**
multidimensional array to one-dimensional array, To delete a label, delete the parent tag, all the child tag IDs get the
* @params array $tree The information read from the database bool $getTagName returns the label name, FALSE only returns the label ID
* BOOL $getGr Ouptag whether to return the Child Group label (valid only when the label name is returned) array $ret the initial value of the recursive call
* @return Array $ret The list of IDs returned, or Id=>array (' TagName ' =>name, ' ta GType ' =>val ' array list, Tattype 0 for normal tag 1 for group Tag * */
static function Array_multi_to_single ($tree, $getTagName = Fals E, $getGroupTag = true, $ret = Array ())
{
foreach ($tree as $k + $v) {
if (!empty ($v [' child ')]) {
$ret = Self::array_multi_to_single ($v [' Child '], $getTagName, $getGroupTag, $ret);
}
if ($getTagName) {
if (isset ($v [' Child '])} {
if ($getGroupTag) {
$ret [$v [' id ']] = $v [' name '];
}
}else{
$ret [$v [' id ']] = $v [' name '];
}
}else{
Array_push ($ret, $v [' id ']);
}
}
return < Span style= "color: #cc7832;" >< Span style= "color: #9876aa;" >< Span style= "color: #629755; Font-style:italic; " > $ret;}
Database value three-level classification background traversal