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

WBOY
发布: 2016-07-28 08:30:04
原创
977 人浏览过

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

核心代码如下:

<span>php 
</span><span>$now</span>=<span>time</span><span>(); 
</span><span>$oc</span> = <span>array</span><span>( 
</span>'team_type' => 'normal', 
"begin_time $now}'", 
"end_time > '{<span>$now</span>}'",<span>
); 
</span><span>$p</span>="p2"<span>; 
</span><span>$pp1</span>=""<span>; 
</span><span>$pp2</span>=""<span>; 
</span><span>$now</span> = <span>time</span><span>(); 
</span><span>switch</span> (<span>$p</span><span>) 
{ 
</span><span>case</span> "p1": 
<span>$pp1</span>="team_price ; 
<span>$pp2</span>=""<span>; 
</span><span>break</span><span>; 
</span><span>case</span> "p2": 
<span>$pp1</span>="team_price > 10"<span>; 
</span><span>$pp2</span>="team_price ; 
<span>break</span><span>; 
</span><span>case</span> "p3": 
<span>$pp1</span>="team_price > 50"<span>; 
</span><span>$pp2</span>="team_price ; 
<span>break</span><span>; 
</span><span>case</span> "p4": 
<span>$pp1</span>="team_price > 100"<span>; 
</span><span>$pp2</span>="team_price ; 
<span>break</span><span>; 
</span><span>case</span> "p5": 
<span>$pp1</span>="team_price > 200"<span>; 
</span><span>$pp2</span>=""<span>; 
</span><span>break</span><span>; 
</span><span>default</span>: 
<span>$pp1</span>=""<span>; 
</span><span>$pp2</span>=""<span>; 
} 
</span><span>if</span>(!<span>empty</span>(<span>$pp1</span><span>)){ 
</span><span>array_push</span>(<span>$oc</span>,<span>$pp1</span><span>); 
} 
</span><span>if</span>(!<span>empty</span>(<span>$pp2</span><span>)){ 
</span><span>array_push</span>(<span>$oc</span>,<span>$pp2</span><span>); 
} 
</span><span>print_r</span>(<span>$oc</span><span>); 
</span><span>/*</span><span> 何问起 hovertree.com </span><span>*/</span>?>
登录后复制

因为是多条件查询所以需要先判断是否为空,然后再添加到数组里面。

推荐:http://www.cnblogs.com/roucheng/p/3528396.html

以上就介绍了 php 数组动态添加实现代码最土团购系统的价格排序,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板