我有这个代码:
if($coupon->excluding_discounted){
if(!$product->price_after_discount){
// do something
}
}
代码运行得很好,但我想如果。。。
dd($coupon->excluding_discounted,!$product->price_after_discount);
1
false
如何检查某个元素的值是否为1,而另一个元素是否为false来做某事。。。?
更新:
我的完整代码:
$products->map(function($product) use($coupon){
if($coupon->excluding_discounted && !$product->price_after_discount){
user()->cart()->updateExistingPivot($product, [
'coupon_id' => $coupon->id,
]);
}
});
代码的逻辑是,如果产品有折扣,并且优惠券中的excluding_discounted为true,则重置代码
我试过这样做,但它存储coupon_id,即使产品有折扣!但如果内部工作完美,则使用
您可以将if
语句连接在一起,如下所示:
if ($coupon->excluding_discounted && !$product->price_after_discount) {
// do something
}
如果您想严格测试变量的值,可以使用===运算符:
if (1 === $coupon->excluding_discounted
&& false === $product->price_after_discount
) {
// do something here
}