Maison > php教程 > php手册 > le corps du texte

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

WBOY
Libérer: 2016-07-06 14:25:13
original
1618 Les gens l'ont consulté

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>
?>
Copier après la connexion

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

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

Étiquettes associées:
php
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
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!