title: PHP How to code shopping cart with special description?
body: <p>I have a $cart array(), it's a session variable before posting to database.</p>
  
  <pre><code>array (size=2)
    1 =&gt; 
      array (size=5)
        'id' =&gt; string '1' (length=1)
        'price' =&gt; string '10' (length=2)
        'qty' =&gt; int 2
        'item_desc' =&gt; string 'Fast Food 01' (length=12)
        'special_desc' =&gt; string '' (length=0)
    '1S' =&gt; 
      array (size=5)
        'id' =&gt; string '1' (length=2)
        'price' =&gt; string '10' (length=2)
        'qty' =&gt; string '1' (length=1)
        'item_desc' =&gt; string 'Fast Food 01' (length=12)
        'special_desc' =&gt; string 'Special Cook style 1' (length=3)
  </code></pre>
  
  <p>As the example, the item id is "1", but to avoid conflict of duplicate key, I put "S" to indicate it's an array element with special description.</p>
  
  <p>This is my current coding</p>
  
  <pre><code>...
  if (array_key_exists($item_id, $cart)) {
    $key_item_id = $item_id . 'S';
  }
  
  $cart[$key_item_id] = array('id' =&gt; $item_id, 'price' =&gt; $price, 'qty' =&gt; $qty, 'item_desc' =&gt; $item_desc, 'special_desc' =&gt; $special_desc);
  ...
  </code></pre>
  
  <p>However, there may be a possibility that there are more than one special descriptions, so I think it should have a counter number after and "S" e.g. "1S1" to represent item id "1" with special descriptions style 1, "1S2" with special description style 2 and so on.</p>
  
  <pre><code>array (size=2)
    1 =&gt; 
      array (size=5)
        'id' =&gt; string '1' (length=1)
        'price' =&gt; string '10' (length=2)
        'qty' =&gt; int 2
        'item_desc' =&gt; string 'Fast Food 01' (length=12)
        'special_desc' =&gt; string '' (length=0)
    '1S1' =&gt; 
      array (size=5)
        'id' =&gt; string '1' (length=2)
        'price' =&gt; string '10' (length=2)
        'qty' =&gt; string '1' (length=1)
        'item_desc' =&gt; string 'Fast Food 01' (length=12)
        'special_desc' =&gt; string 'Special Cook style 1' (length=3)
  
    '1S2' =&gt; 
      array (size=5)
        'id' =&gt; string '1' (length=2)
        'price' =&gt; string '10' (length=2)
        'qty' =&gt; string '1' (length=1)
        'item_desc' =&gt; string 'Fast Food 01' (length=12)
        'special_desc' =&gt; string 'Special Cook style 2' (length=3)
  </code></pre>
  
  <p>My question is how to "count" the $cart that how many item id "1" with special description so I can realize the current counter of it?</p>
  
  <p>Thanks.</p>