Re: md arrays

From: Date: Wed, 22 Sep 2004 06:46:39 +0000
Subject: Re: md arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197522@lists.php.net to get a copy of this message
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


« previous php.general (#197522) next »