[eluser]digitaleye[/eluser]
Hi
I need a little help with a function.
I am trying to search through a multi dimensional array (the Codeigniter cart) to find any items that have an id of a certain value.
Each item in the cart has the basic values (id, price etc). While displaying all items (in a foreach loop) i want to see if that item is already in the cart and return TRUE/FALSE.
The code i have for the function is :
Code:
function isInCart($array, $key, $value)
{
# check if an item is in the cart
foreach($array as $item) {
if($item[$key] == $value) {
return TRUE;
} else {
return FALSE;
}
}
}
And i am passing in
Code:
$this->cart->contents()
as the array
'id' as the key to search (in this case the id
and
which is the item id generated from the foreach loop in the view.
However, it only seems to work for the first value in the array.
Any help would be gratefully appreciated.
Thanks