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! Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
kevin7 Posted August 21, 2007 Author Share Posted August 21, 2007 thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.