search
Homephp教程php手册php无限级分类(带层深)算法

php无限级分类(带层深)算法

Jun 06, 2016 pm 07:55 PM
linuxphpClassificationunlimitedCommunityalgorithmEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 分享一个利用数组来实现无限级分类php类程序,有需要的朋友可参考,这里就不多说什么了直接复制上代码。 代码: ?php $cates = array( array( 'cid' = 1, 'cname' = '新闻', 'pid' = 0 ), array

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  分享一个利用数组来实现无限级分类php类程序,有需要的朋友可参考,这里就不多说什么了直接复制上代码。

  代码:

  

  $cates = array(

  array(

  'cid'   => 1,

  'cname' => '新闻',

  'pid'   => 0

  ),

  array(

  'cid'   => 2,

  'cname' => '通知',

  'pid'   => 0

  ),

  array(

  'cid'   => 3,

  'cname' => '国内新闻',

  'pid'   => 1

  ),

  array(

  'cid'   => 4,

  'cname' => '国际新闻',

  'pid'   => 1

  ),

  array(

  'cid'   => 5,

  'cname' => '北京新闻',

  'pid'   => 3

  ),

  array(

  'cid'   => 6,

  'cname' => '上海新闻',

  'pid'   => 3

  ),

  array(

  'cid'   => 7,

  'cname' => '紧急通知',

  'pid'   => 2

  ),

  array(

  'cid'   => 8,

  'cname' => '一般通知',

  'pid'   => 2

  ),

  );

  /**

  * 生成菜单

  *

  * @param array $data 原始数据

  * @param integer $pid 当前分类的父id

  * @return array 处理后数据

  */

  function createMenuTree($data = array(), $pid = 0)

  {

  if (empty($data))

  {

  return array();

  }

  static $level = 0;

  $returnArray = array();

  foreach ($data as $node)

  {

  if ($node['pid'] == $pid)

  {

  $returnArray[] = array(

  'cid'   => $node['cid'],

  'cname' => $node['cname'],

  'level' => $level

  );

[1] [2] 

php无限级分类(带层深)算法

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),