kevin7 Posted August 21, 2007 Share Posted August 21, 2007 hmmm, let say if i have the following array data im building a shopping cart, and im having the following problem. the array in the bottom is the way i store customer's product and quantity. For example, refer to below, product 3's quantity is 2. $item['product1'] = 1; $item['product2'] = 4; $item['product3'] = 2; $item['product4'] = 1; the problem im having is, how am i suppose to display the product? is it any function to list out the array index? i tried print_r, it did list out, but, it isnt the thing i want... i want an output like the following so that i can use the product id to retrieve the product information from database... product1 : 1 product2 : 4 product3 : 2 product4 : 1 thank a lot! Link to comment https://forums.phpfreaks.com/topic/65923-solved-array-index-problem/ Share on other sites More sharing options...
vijayfreaks Posted August 21, 2007 Share Posted August 21, 2007 Hi.. For that use the following code: <?php $item['product1'] = 1; $item['product2'] = 4; $item['product3'] = 2; $item['product4'] = 1; foreach($item as $key=>$val) { echo $key.": ".$val."<br/>"; } ?> this will output like: product1 : 1 product2 : 4 product3 : 2 product4 : 1 Regards, Vijay Link to comment https://forums.phpfreaks.com/topic/65923-solved-array-index-problem/#findComment-329543 Share on other sites More sharing options...
kevin7 Posted August 21, 2007 Author Share Posted August 21, 2007 thanks! Link to comment https://forums.phpfreaks.com/topic/65923-solved-array-index-problem/#findComment-329549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.