php array dynamically adds the price ordering of the implementation code of
- 2020-05-10 17:50:43
- OfStack
The core code is as follows:
Because it is a multi-conditional query, you need to determine if it is null before you add it to the array.
<?php
$now=time();
$oc = array(
'team_type' => 'normal',
"begin_time < '{$now}'",
"end_time > '{$now}'",
);
$p="p2";
$pp1="";
$pp2="";
$now = time();
switch ($p)
{
case "p1":
$pp1="team_price < 10";
$pp2="";
break;
case "p2":
$pp1="team_price > 10";
$pp2="team_price < 50";
break;
case "p3":
$pp1="team_price > 50";
$pp2="team_price < 100";
break;
case "p4":
$pp1="team_price > 100";
$pp2="team_price < 200";
break;
case "p5":
$pp1="team_price > 200";
$pp2="";
break;
default:
$pp1="";
$pp2="";
}
if(!empty($pp1)){
array_push($oc,$pp1);
}
if(!empty($pp2)){
array_push($oc,$pp2);
}
print_r($oc);
?>
Because it is a multi-conditional query, you need to determine if it is null before you add it to the array.