【发布时间】:2020-09-03 06:58:50
【问题描述】:
我对算法不太熟悉,请有人帮我将此 for 循环转换为 foreach
for($i = 0; $i < count($cartBookItems); $i++) {
$currentCartBookItem = $cartBookItems[$i];
if($currentCartBookItem->getBookID() == $book->getId()) {
$newQuantity = $currentCartBookItem->getQuantity() + $quantity;
$currentCartBookItem->setQuantity($newQuantity);
$isItemAlreadyExists = true;
}
}
【问题讨论】:
-
这里出现的第一个问题是:为什么?
标签: php algorithm for-loop foreach