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

WBOY
Libérer: 2016-07-28 08:30:04
original
977 Les gens l'ont consulté

最近在实现最土团购系统的价格排序功能,需要对$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>?>
Copier après la connexion

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

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

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

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal