Home > Backend Development > PHP Tutorial > PHP city-linked classification sorting program_PHP tutorial

PHP city-linked classification sorting program_PHP tutorial

WBOY
Release: 2016-07-13 16:56:49
Original
927 people have browsed it

A netizen wrote a PHP classification program for linking prefectures and cities. You can refer to it.

Write a function to convert the data

 代码如下 复制代码
$array = array(
    0=>array("","河北"),
    1=>array("","北京"),
    2=>array(0,"保定"),
    3=>array(1,"海淀"),
    4=>array(3,"中关村"),
    5=>array(2,"涿州")
);


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;
}
Copy code
function typeArray($array){
$con = null; foreach ($array as $k=>$v){

$na[$k] = is_numeric($v[0]) ? $na[$v[0]].$k."|" : $k."|";

} foreach ($na as $k=>$v){ $s = substr_count($v,"|"); $con .= str_repeat("-",($s-1)).$array[$k][1]."n"; } Return $con; }
http://www.bkjia.com/PHPjc/631581.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631581.htmlTechArticleA php classification program for prefecture-city linkage written by a netizen, you can refer to it. Write a function to convert the data. The code is as follows. Copy the code $array = array( 0=array(,Hebei), 1=array(,Beijing),...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template