Home > php教程 > php手册 > body text

php 数组动态添加实现代码(最土团购系统的价格排序)

WBOY
Release: 2016-06-06 20:39:44
Original
1137 people have browsed it

最近在实现最土团购系统的价格排序功能,需要对$oc数组进行扩展,经过测试用下面的方法即可。

核心代码如下:
代码如下:
$now=time();
$oc = array(
'team_type' => 'normal',
"begin_time "end_time > '{$now}'",
);
$p="p2";
$pp1="";
$pp2="";
$now = time();
switch ($p)
{
case "p1":
$pp1="team_price $pp2="";
break;
case "p2":
$pp1="team_price > 10";
$pp2="team_price break;
case "p3":
$pp1="team_price > 50";
$pp2="team_price break;
case "p4":
$pp1="team_price > 100";
$pp2="team_price break;
case "p5":
$pp1="team_price > 200";
$pp2="";
break;
default:
$pp1="";
$pp2="";
}
if(!empty($pp1)){
array_push($oc,$pp1);
}
if(!empty($pp2)){
array_push($oc,$pp2);
}
print_r($oc);

?>

因为是多条件查询所以需要先判断是否为空,然后再添加到数组里面。
Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template