A
A
Anton2018-03-21 04:33:18
PHP
Anton, 2018-03-21 04:33:18

How to fix output condition from php array?

while ($arItems = $dbBasketItems->Fetch())
{
$arBasketItems[] = $arItems;
//print ($arItems[PRODUCT_ID]); выведет без пробелов 12804 12805 12806 20910
if ($arCurOffer['ID'] == $arItems[PRODUCT_ID]) 
echo 'Уже в корзине'; else echo 'Купить';
}

Displays for products:
BuyBuyBuyAlready in the cart

instead of
Buy

or
Already in cart

those. I have it displayed 4 times instead of one, exactly according to the number of goods in the (basket) $arItems[PRODUCT_ID]. How to withdraw once?
The meaning is that if such a product $arItems[PRODUCT_ID] is present in the cart, then the name of the button $arCurOffer['ID'] should be changed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Lezhnin, 2018-03-21
@anton99zel

You basically have a list of goods. Given that this is Bitrix, we will not change the logic:

$inBasket = false;
while ($arItems = $dbBasketItems->Fetch())
{
    $arBasketItems[] = $arItems;
    //print ($arItems[PRODUCT_ID]); выведет без пробелов 12804 12805 12806 20910
    if ($arCurOffer['ID'] == $arItems['PRODUCT_ID']){ // Пожалуйста, ключ массива заключайте в кавычки, пишите правильно.
        $inBasket = true;
     }
}
echo $inBasket ? 'Уже в Корзине' : 'Купить';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question