Home >Backend Development >PHP Tutorial >PHP array dynamically adds implementation code (price sorting of the most popular group buying system), array group buying_PHP tutorial
Recently implementing the price sorting function of the Tutu group buying system, the $oc array needs to be To expand, use the following method after testing.
The core code is as follows:
<?<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> ?>
Because it is a multi-condition query, you need to first determine whether it is empty, and then add it to the array.
Recommended: http://www.cnblogs.com/roucheng/p/3528396.html