Jump to content

[SOLVED] brains stopped working :'( think i need to get the name of an array


dt192

Recommended Posts

I've got a session array like

 

$_SESSION['cart'][$product_id]['name']="item1";

$_SESSION['cart'][$product_id]['price']="100.00";

 

but all set dynamicly you get the idea, well when i want to display the data in the cart i use something along the lines of:

 

if($_SESSION['cart']) { //if the cart isn't empty

foreach($_SESSION['cart'] as $product_id){

echo '['.$product_id['name'].'-'.$product_id['price'].']<br/>';}

}

 

but for example just before each item name in the cart i have a remove icon so i need the actual value of $product_id as a string so i can pass it to the remove function or do i lol?

thats funny because thats exactly what i had before i changed it lol see i knew my brain wasnt working i should get some more sleep lol but yes:

 

if($_SESSION['cart']) {  //if the cart isn't empty

  foreach($_SESSION['cart'] as $product_id => $product){

      echo '['.$product_id.'-'.$product['name'].'-'.$product['price'].']<br/>';}

}

 

gave me exactly the result i was after thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.