Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
你能帮我简化PHP中的代码吗_Php - Fatal编程技术网

你能帮我简化PHP中的代码吗

你能帮我简化PHP中的代码吗,php,Php,我如何简化这一点 我试图使$quantity具有两个值 我可以使用或运算符吗 谢谢你回答你的问题,不,你不能这样使用或陈述 您可以做的是根据您获得的数据有条件地生成$quantity,例如: $quantity = $fetch_barcode['item_price'] / $item->unit_price; $quantity = $fetch_barcode['item_price'] / $item_kit->unit_price; 那么您的数量等于您的商品价格/单价或商

我如何简化这一点

我试图使
$quantity
具有两个值

我可以使用或运算符吗


谢谢你回答你的问题,不,你不能这样使用或陈述

您可以做的是根据您获得的数据有条件地生成
$quantity
,例如:

$quantity = $fetch_barcode['item_price'] / $item->unit_price;
$quantity = $fetch_barcode['item_price'] / $item_kit->unit_price;

那么您的数量等于您的商品价格/单价或商品价格/单价,您想知道如何简化这一点吗?@kerbholz嗨,我正在尝试使用2个函数获得$quantity,1)$fetch_barcode['item_price']/$item_kit->unit_price;2) $fetch_条码['item_price']/$item->单价;基于什么条件?如“如果未设置$item->unit\u price,请使用$item\u kit->unit\u price”?我试图实现的是$quantity可以有多个值?如何做到这一点?正如@kerbholz所说的,所有的条件都是真实的,所以在你的例子中,
$quantity=!空($item->单价)$取货条码['item\u price']/$item->unit\u price:$fetch\u条码['item\u price']/$item\u kit->unit\u price
$price = !empty($item->unit_price) ? $item->unit_price : $item_kit->unit_price;
$quantity = $fetch_barcode['item_price'] / $price