[英]Can you help me to simplify codes OR in PHP
$quantity = $fetch_barcode['item_price'] / $item->unit_price;
$quantity = $fetch_barcode['item_price'] / $item_kit->unit_price;
How can I simplify this?我怎样才能简化这个?
I am trying to make $quantity
have two values.我试图让
$quantity
有两个值。
Can I use OR Operators?我可以使用 OR 运算符吗?
Thank you谢谢
In answer to your question, no, you can't use OR statements this way.回答您的问题,不,您不能以这种方式使用 OR 语句。
What you can do is make $quantity
conditionally based on the data you've got, for example:您可以做的是根据您获得的数据有条件地制作
$quantity
,例如:
$price = !empty($item->unit_price) ? $item->unit_price : $item_kit->unit_price;
$quantity = $fetch_barcode['item_price'] / $price
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.