Answer the question
In order to leave comments, you need to log in
How to compare variable and multidimensional array?
I have such a problem, I have a variable and a multidimensional array
The array is stored in the session
Array
(
[107] => Array
(
[SIMPLE_BASKET_TITLE] => Black Burger
[SIMPLE_BASKET_QUO] => 1
[SIMPLE_BASKET_PRICE] => 180
[SIMPLE_BASKET_CATEGORY] => kfc
)
)
// сам массив $this->items <b>(Результат вывода написан выше)</b>
// $catraw - ПЕРЕМЕННАЯ которая допустим хранит в себе значение <b>(kfc)</b>
// Если такой элемент уже есть...
if (array_key_exists($id, $this->items))
{
// Увеличим количество
$this->items[$id][self::QUO]++;
}
else
{
//Проверка на то что в корзине присутствует товар из категории,
//которой мы добаляем товары, если же нет, то очищаем корзину
//и добавляем товар из другой категории
if(in_array($catraw, $this->items)
{
// Добавим элемент
$this->items[$id] = array
(
self::TITLE => $title,
self::QUO => 1,
self::PRICE => $price,
self::CATEGORY => $category
);
} else {
$this->items = array(); // ЭТО СТРОКА ОЧИЩАЕТ КОРЗИНУ
// Добавим элемент
$this->items[$id] = array
(
self::TITLE => $title,
self::QUO => 1,
self::PRICE => $price,
self::CATEGORY => $category
);
}
Answer the question
In order to leave comments, you need to log in
Thanks everyone! All options are great! Found another way, pushed the category into the session, and compare it!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question