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

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

WBOY
Release: 2016-07-06 14:25:13
Original
1617 people have browsed it

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>
?>
Copy after login

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

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

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!