This article is a detailed analysis and introduction to the implementation of regional classification sorting algorithm using PHP. Friends who need it can refer to
Write a function to convert the data
$array = array(
0=>array("","Hebei"),
1=>array("","Beijing"),
2=> array(0,"Baoding"),
3=>array(1,"Haidian"),
4=>array(3,"Zhongguancun"),
5=>array( 2,"Zhuozhou")
);
After processing, the return is as follows:
Hebei
-Baoding
--Zhuozhou
Beijing
-Haidian
--Zhongguancun
The code is as follows:
function typeArray($array){ $con = null; foreach ($array as $k=>$v){ $na[$k] = is_numeric($v[0]) ? $na[$v[0]].$k."|" : $k."|"; } asort($na); //排序 foreach ($na as $k=>$v){ $s = substr_count($v,"|"); $con .= str_repeat("-",($s-1)).$array[$k][1]."\n"; } return $con; }
The above is the detailed content of PHP regional classification sorting algorithm example code. For more information, please follow other related articles on the PHP Chinese website!