This article provides a detailed analysis of the regional classification sorting algorithm using php. For more information, see
This article provides a detailed analysis of the regional classification sorting algorithm using php. For more information, see
Write a function
$ Array = array (
0 => array ("", "Hebei "),
1 => array ("", "Beijing "),
2 => array (0, "Baoding "),
3 => array (1, "Haidian "),
4 => array (3, "Zhongguancun "),
5 => array (2, "Bozhou ")
);
The returned result is as follows:
Hebei
-Baoding
-- Bozhou
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); // sort
Foreach ($ na as $ k => $ v ){
$ S = substr_count ($ v, "| ");
$ Con. = str_repeat ("-", ($ s-1). $ array [$ k] [1]. "\ n ";
}
Return $ con;
}
, Hong Kong server, server space, website Space