Home > Backend Development > PHP Tutorial > PHP infinite classification recursive function implementation

PHP infinite classification recursive function implementation

巴扎黑
Release: 2016-11-22 09:29:24
Original
1254 people have browsed it

/**

*

* @param All arrays $array

* @param Current user ID $id

* @param Storage variables $str

* @return string

*/

function findIds($array,$id,$str='') {

$result = findChild($array,$id);//Get all the same items under the current node Level child node

foreach ($result as $k => $v){

//Assign value to variable

$str.=$v['id'].',';

//Call again This function displays the sibling child nodes under the child node

findIds($array,$v['id'],&$str);

}

return $str; //Return variable

}

//Get all sibling child nodes under the current node

function findChild(&$arr,$id){

$childs=array();

foreach ($arr as $k => $v) {

if($v['pid']== $id){

$childs[]=$v;

}

}

return $childs;

}


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template