I suggest you to use something like this as your cart:

  $cart => Array
    (
      [LT4697] => Array
        (
          [qty] => 1
        )
      [LT1234] => Array
        (
          [qty] => 2
        )
    )

So you can easily check with in_array() / is_array() if product is in the cart allready.


Niklas




Justin French wrote:
I have an array that looks something like this:

    $cart => Array
        (
            [0] => Array
                (
                    [id] => LT4697
                    [qty] => 1
                )

            [1] => Array
                (
                    [id] => LT4153
                    [qty] => 3
                )

            [2] => Array
                (
                    [id] => LT4697
                    [qty] => 1
                )
            )

I'm aware that I probably could just have a single dimension array, but there's more to be added later, and I prefer to treat this data like rows from mysql.

Anyway, what's the *least expensive* way to:

- check if an item (eg LT4153) is in the cart already?
- get the current qty of an item (eg LT4153)

The cart won't be big, so a foreach() on the cart isn't out of question, but I'd like to know the *right* way :)


TIA Justin

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to