Web Analytics Made Easy -
StatCounter Array problem - CodingForum


No announcement yet.

Array problem

  • Filter
  • Time
  • Show
Clear All
new posts

  • Array problem

    Alright, I'm storing shopping cart in my database as productid:quantity;

    So for example, 4:1;5:2; would mean 1 Product 4 and 2 Product 5s

    I've been using this script:

    PHP Code:
    $cart explode(';',$cart);

    foreach (
    $cart as $key => $value) {

    $stock_id=substr($cart[$key], 01); // Product
    $qty=substr($cart[$key], -11); // Qty 
    However, I just realized this won't work for double digits, IE 10:1;

    How can I say, grab all digits before the colon or after the colon, or is there just an easier way to be working with this array?

    Thanks in advance.

  • #2
    Explode it again.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).


    • #3
      serialize() and then store them.
      I'm not sure if this was any help, but I hope it didn't make you stupider.

      Experience is something you get just after you really need it.
      PHP Installation Guide Feedback welcome.