示例 - 假设我们有以下二维数组 -
Array
(
[0] => Array
(
[id] => 6
[order_id] => 246
[court_price_id] => 1048
[time_from] => 15:30
[time_to] => 16:00
[booking_date_from] => 2018-03-28
[booking_date_to] => 2018-03-28
[court_price] => 350
[booking_status] => booked
[created] => 2018-03-28 15:19:34
[pricetype] => hour
)
[1] => Array
(
[id] => 7
[order_id] => 246
[court_price_id] => 1049
[time_from] => 07:00
[time_to] => 07:30
[booking_date_from] => 2018-03-29
[booking_date_to] => 2018-03-29
[court_price] => 350
[booking_status] => booked
[created] => 2018-03-28 15:19:34
[pricetype] => hour
)
)
Array
(
[0] => Array
(
[id] => 8
[order_id] => 247
[court_price_id] => 1048
[time_from] => 07:00
[time_to] => 07:30
[booking_date_from] => 2018-03-28
[booking_date_to] => 2018-03-28
[court_price] => 350
[booking_status] => booked
[created] => 2018-03-28 15:19:51
[pricetype] => hour
)
)
我试过了: -
$date = date("Y-m-d");
foreach($bookdata as $values)
{
if($values['booking_date_from'] == $date)
{
echo "1";
}
else
{
echo "2";
}
}
我想如果在数组中预设日期然后打印1,如果日期大于当前日期,则打印2。
答案 0 :(得分:1)
I got Answer -
$flag = 0;
if(count($bookdata) > 1){
foreach ($bookdata as $key => $value) {
$date = strtotime($value['booking_date_to']);
if($date > $today){
$flag = 1;
break;
}
}
$id = $bookdata[0]['order_id'];
if($flag == 0){
$qry = "Update payments set booking_status=1 where id=".$id;
$results=mysqli_query($conn,$qry);
}
}else{
$date = strtotime($bookdata[0]['booking_date_to']);
$id = $bookdata[0]['order_id'];
if($date < $today){
$qry = "Update payments set booking_status=1 where id=".$id;
$results=mysqli_query($conn,$qry);
}
}