Home > Article > Backend Development > php wireless classification
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.