search
Homephp教程php手册php+mysql简单的无限分类栏目

无限分类原理非常的简单就是找到自己上级目录交级递归去操作,然后再找自己的上级直到最上级为止了,这种就可以实现了无限级分类了,下面看个例子。

一个非常简单清晰简单的无极限分类范例,带缩进效果,只需查询一次数据表,然后递归遍历结果集,就可以了,要在php中实现栏目缩进显示可以参考一下。

$sql = 'select * from cat order by cat_id desc';
$list = $db->getAll($sql);
$list = getLevelCat($list);
function getLevelCat($catlist, $parent_id='0', $html='   ', $level='0'){
    $arr = array();
    foreach($catlist as $val){
        if($val['parent_id']==$parent_id){
            $val['html'] = str_repeat($html,$level);
            $val['level'] = $level;
            $arr[] = $val;
            $arr = array_merge($arr, getLevelCat($catlist, $val['cat_id'], $html, $level+1));
        }
    }
    return $arr;
}

php无极限分类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
Java ArrayList遍历时使用foreach和iterator删除元素的区别是什么?Java ArrayList遍历时使用foreach和iterator删除元素的区别是什么?Apr 27, 2023 pm 03:40 PM

一、Iterator和foreach的区别多态差别(foreach底层就是Iterator)Iterator是一个接口类型,他不关心集合或者数组的类型;for和foreach都需要先知道集合的类型,甚至是集合内元素的类型;1.为啥说foreach底层就是Iterator编写的代码:反编译代码:二、foreach与iterator时remove的区别先来看阿里java开发手册但1的时候不会报错,2的时候就会报错(java.util.ConcurrentModificationException)首

php如何判断foreach循环到第几个php如何判断foreach循环到第几个Jul 10, 2023 pm 02:18 PM

​php判断foreach循环到第几个的步骤:1、创建一个“$fruits”的数组;2、创建一个计数器变量“$counter”初始值为0;3、使用“foreach”循环遍历数组,并在循环体中增加计数器变量的值,再输出每个元素和它们的索引;4、在“foreach”循环体外输出计数器变量的值,以确认循环到了第几个元素。

jquery如何隐藏select元素jquery如何隐藏select元素Aug 15, 2023 pm 01:56 PM

jquery隐藏select元素的方法:1、hide()方法,在HTML页面中引入jQuery库,可以使用不同选择器来隐藏select元素,ID选择器将selectId替换为你实际使用的select元素的ID;2、css()方法,使用ID选择器选择需要隐藏的select元素,使用css()方法将display属性设置为none,并将selectId替换为select元素的ID。

PHP返回一个键值翻转后的数组PHP返回一个键值翻转后的数组Mar 21, 2024 pm 02:10 PM

这篇文章将为大家详细讲解有关PHP返回一个键值翻转后的数组,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。PHP键值翻转数组键值翻转是一种对数组进行的操作,它将数组中的键和值进行交换,生成一个新的数组,其中原始键作为值,原始值作为键。实现方法在php中,可以通过以下方法对数组进行键值翻转:array_flip()函数:array_flip()函数专门用于键值翻转操作。它接收一个数组作为参数,并返回一个新的数组,其中键和值已交换。$original_array=[

linux要用select的原因是什么linux要用select的原因是什么May 19, 2023 pm 03:07 PM

因为select可以使开发者在同时等待多个文件缓冲区,可减少IO等待的时间,能够提高进程的IO效率。select()函数是IO多路复用的函数,允许程序监视多个文件描述符,等待所监视的一个或者多个文件描述符变为“准备好”的状态;所谓的”准备好“状态是指:文件描述符不再是阻塞状态,可以用于某类IO操作了,包括可读,可写,发生异常三种。select是一个计算机函数,位于头文件#include。该函数用于监视文件描述符的变化情况——读写或是异常。1.select函数介绍select函数是IO多路复用的函

PHP返回数组中的当前元素PHP返回数组中的当前元素Mar 21, 2024 pm 12:36 PM

这篇文章将为大家详细讲解有关PHP返回数组中的当前元素,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。获取PHP数组中的当前元素php为访问和操作数组提供了多种方法,其中包括获取数组中的当前元素。以下介绍几种常用的技术:1.current()函数current()函数返回数组内部指针当前指向的元素。指针最初指向数组的第一个元素。使用以下语法:$currentElement=current($array);2.key()函数key()函数返回数组内部指针当前指向元

如何使用forEach函数遍历对象的属性?如何使用forEach函数遍历对象的属性?Nov 18, 2023 pm 06:10 PM

如何使用forEach函数遍历对象的属性?在JavaScript中,我们经常需要对对象的属性进行遍历操作。如果你想使用一种简洁的方法来遍历对象的属性,forEach函数是一个非常好的选择。在本文中,我们将介绍如何使用forEach函数来遍历对象的属性,并提供具体的代码示例。首先,让我们来了解一下forEach函数的基本用法。forEach函数是Java

mysql的select语法怎么使用mysql的select语法怎么使用Jun 01, 2023 pm 07:37 PM

1、SQL语句中的关键词对大小写不敏感,SELECT等效于SELECT,FROM等效于from。2、从users表中选择所有列的,可以用符号*代替列的名称。语法--这是注释--从FEOM指定的[表中],查询出[所有的]数据.*表示[所有列]SELECT*FROM--通过从FROM从指定的[表中],查询出指定列名称(字段)的数据SELECT列名称FROM表名称实例--注意:多个列之间,使用英文的逗号来分隔selectusername,passwordfrom

See all articles

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment