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

WBOY
发布: 2016-07-12 08:50:09
原创
968 人浏览过

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

最近在实现最土团购系统的价格排序功能,需要对$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 < '{<span>$now</span>}'", 
"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 < 10"<span>; 
</span><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 < 50"<span>; 
</span><span>break</span><span>; 
</span><span>case</span> "p3": 
<span>$pp1</span>="team_price > 50"<span>; 
</span><span>$pp2</span>="team_price < 100"<span>; 
</span><span>break</span><span>; 
</span><span>case</span> "p4": 
<span>$pp1</span>="team_price > 100"<span>; 
</span><span>$pp2</span>="team_price < 200"<span>; 
</span><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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1134781.htmlTechArticlephp 数组动态添加实现代码(最土团购系统的价格排序),数组团购 最近在实现最土团购系统的价格排序功能,需要对$oc数组进行扩展,经过测...
相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板