Home php教程 php手册 php实现多级分类筛选程序代码

php实现多级分类筛选程序代码

Jun 02, 2016 am 09:13 AM
foreach

现在这种多选择功能在很多网站都有,如现在很多电商网站都有N个条件选择了,下面小编为各位介绍一个简单的多级分类筛选实现方法。

主要注意这边有一个 $$这是变量的变量。 以后估计会常用这个做开发。

<?php
$conditions = array(&#39;price&#39;,&#39;color&#39;,&#39;metal&#39;);//要进行筛选的字段放在这里
$price = $color = $metal=&#39;&#39;;//先给需要筛选的字段赋空值,这些值将输出到页面的hidden fileds 中
//以下循环给已经进行的筛选赋值,以便能够在下一次筛选中保留
foreach($conditions as $value){
    if(isset($_GET[$value])){ 
        $$value = $_GET[$value];
    }
}
//以下是演示输出$_GET数据
echo &#39;<pre class="brush:php;toolbar:false">&#39;;
print_r($_GET);
echo &#39;
Copy after login
'; ?> 分类筛选演示
价格:不限 100-1000 1001-2000 2001-3000
颜色:红色 蓝色
材质:纯金 纯银


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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? Apr 27, 2023 pm 03:40 PM

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList?

How to determine the number of foreach loop in php How to determine the number of foreach loop in php Jul 10, 2023 pm 02:18 PM

How to determine the number of foreach loop in php

PHP returns an array with key values ​​flipped PHP returns an array with key values ​​flipped Mar 21, 2024 pm 02:10 PM

PHP returns an array with key values ​​flipped

PHP returns the current element in an array PHP returns the current element in an array Mar 21, 2024 pm 12:36 PM

PHP returns the current element in an array

How to iterate through the properties of an object using the forEach function? How to iterate through the properties of an object using the forEach function? Nov 18, 2023 pm 06:10 PM

How to iterate through the properties of an object using the forEach function?

What is the difference between foreach and for loop What is the difference between foreach and for loop Jan 05, 2023 pm 04:26 PM

What is the difference between foreach and for loop

How to get the index value of the current element in php foreach loop How to get the index value of the current element in php foreach loop Mar 23, 2023 am 09:17 AM

How to get the index value of the current element in php foreach loop

What does php foreach mean? What does php foreach mean? Mar 10, 2023 am 09:54 AM

What does php foreach mean?

See all articles