array("","北京"), 2=>array(0,"保定"), 3=>array(1,"海淀"), 4=>arr">
当前位置:Gxlcms > PHP教程 > php地区分类排序算法_PHP教程

php地区分类排序算法_PHP教程

时间:2021-07-01 10:21:17 帮助过:14人阅读

写一个函数,将数据
$array = array(
0=>array("","河北"),
1=>array("","北京"),
2=>array(0,"保定"),
3=>array(1,"海淀"),
4=>array(3,"中关村"),
5=>array(2,"涿州")
);
处理后返回如下:
河北
-保定
--涿州
北京
-海淀
--中关村
代码如下:
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;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327956.htmlTechArticle写一个函数,将数据 $array = array( 0=array("","河北"), 1=array("","北京"), 2=array(0,"保定"), 3=array(1,"海淀"), 4=array(3,"中关村"), 5=array(2,"涿州") ); 处理...

人气教程排行