Home  >  Article  >  Backend Development  >  php wireless classification

php wireless classification

WBOY
WBOYOriginal
2016-08-08 09:28:03859browse

A PHP wireless classification method that was used a long time ago, using a recursive idea, is shared with everyone here

//$data is the classification data taken out from the database, $pid is the upper-level classification id, and $level is the classification. Level, here it is limited to level 10, $keyword is the category name

function genCate($data, $pid =0, $level = 0,$keyword)
{
if($level ==10)break;
$l        = str_repeat("    ", $level);
$l        = $l.'└';
static $arrcat  = array();
$arrcat   =empty($level) ? array() :$arrcat;
foreach($data as $k => $row)
	{
	if($row['pid']==$pid)
		{
		$row[$keyword]  = $l.$row[$keyword];
		$row['level']   =$level;
		$arrcat[]     = $row;
		genCate($data,$row['id'], $level+1,$keyword);
		}
	}
	return $arrcat;
}

The above introduces the PHP wireless classification, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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