【发布时间】:2018-08-17 16:51:12
【问题描述】:
我想拆分具有相同日期和不同日期的项目。
foreach ($cart->getAllItems() as $item)
{
$pickupDateTime = $item->getCartPickupDate().' '.$itemgetCartPickupTime();
$pickupDateTime = date('Y-m-d G:i:s', strtotime($pickupDateTime)) //2018-03-09 6:03:00 or 2018-03-09 21:10:00
// Split items here with same Date //
if(Dates are Same Condition){
$items_normal[]= $item->getProductId();
}else
{
//If Dates Are diffrent
$ites_special[]= $item->getProductId();
}
}
需要比较第一个if条件中的日期是否相同,否则需要比较日期不同的项目。
看下面的数组,在这个我有相同的日期和时间,我需要去俱乐部那些有相同的日期和时间。在下面的例子中,第三个必须在第一个数组下,因为它有不同的时间,即 6:05 而不是 6:03
Array
(
[1] => Array
(
[product_id] => 742
[qty] => 1
[date] => 03/09/2018
[time] => 06:03 AM
[tax] => 0
[splinst] => null
)
[2] => Array
(
[product_id] => 743
[qty] => 1
[date] => 03/09/2018
[time] => 06:03 AM
[tax] => 0
[splinst] => null
)
)
Array
(
[3] => Array
(
[product_id] => 744
[qty] => 1
[date] => 03/09/2018
[time] => 06:03 AM
[tax] => 0.12
[splinst] => null
)
[4] => Array
(
[product_id] => 757
[qty] => 1
[date] => 03/09/2018
[time] => 06:05 AM
[tax] => 0.25
[splinst] => null
)
)
【问题讨论】:
-
为此,您可以将 daets 保存在数组中并使用
is_array()来检查同一日期 -
我们如何检查 in_array 是否有相同的日期对象?
-
你只有一个相同的日期吗?
-
不,多个日期时间可以相同
标签: php arrays sorting datetime php-5.6