Monday 15 July 2013

session - How can I resolve repeated $_SESSION values, ADD do Cart PHP? -


I'm shopping shopping only with session variants I do not want anything simple, no databases, it's only the initial system (Later it may use databases and logins)

I click on a product and use the URL to use the session

Example product: Orange

posted url

  site.com/?page=buy&add=Orange&type=fruit   

then .. .

  session_start (); // if 'does not exist already, then' create cart '(if! (Isset ($ _ session [' SHOPPING_CART '])) {$ _SESSION [' SHOPPING_CART '] = array ();} If (isset ($ _GET ['add'])) // // Add an item // it's $ ART = array in the array (// item name 'name' = & gt; $ _GET ['add'], 'type' = & Gt; $ _GET ['tip'], // item value);   

To print, I use it:

  $ itemType = ""; $ Item (number $ [$ item ['type']) {// Skip Skip to ... {$ item_number = & gt; $ item} as foreign currency ($ {_SESSION ['SHOPPING_CART'] ...) Do not do other} Perkin '];} Echo $ item [' name ']; $ itemType = $ item [' type '];}   

However, I have a problem. , Then fruit:

Print:

  Fruits: Banana Banana Food: Meat Fruit: Apple   

Print: Fruits: Banana Apple Food: Meat X

array_nank one ????

Example:

  $ items = array ('key1' = & gt; 'orange', 'key2' = & gt; 'banana', with an array Removes duplicate values. 'Key4' = & gt; 'Orange', 'Key5' =>, 'Lemon',); // first print_r print_r ($ item); $ Items = array_unique ($ item); // second print_a print_a ($ item);   

The output of print_r first:

  array ([key1] => orange [key2] => banana [key4] => ; Orange [Key5] => lemon)   

Output of other print_urds:

  array ([key1] => orange [key2] = & Gt; banana [key5] => lemon)    

No comments:

Post a Comment