dt192 Posted April 18, 2009 Share Posted April 18, 2009 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? Link to comment https://forums.phpfreaks.com/topic/154645-solved-brains-stopped-working-think-i-need-to-get-the-name-of-an-array/ Share on other sites More sharing options...
soak Posted April 18, 2009 Share Posted April 18, 2009 I think you want: <?php if($_SESSION['cart']) { //if the cart isn't empty foreach($_SESSION['cart'] as $product_id => $product){ echo '['.$product['name'].'-'.$product['price'].']<br/>';} } EDIT: to add code tags Link to comment https://forums.phpfreaks.com/topic/154645-solved-brains-stopped-working-think-i-need-to-get-the-name-of-an-array/#findComment-813194 Share on other sites More sharing options...
dt192 Posted April 18, 2009 Author Share Posted April 18, 2009 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 Link to comment https://forums.phpfreaks.com/topic/154645-solved-brains-stopped-working-think-i-need-to-get-the-name-of-an-array/#findComment-813198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.