2

I have added my product id as a key for session cart array. for example 3 and 47.Now when I go to cart page I have text field in where there is quantity box and update button beside it, so I need something when click on update button so it can take it and update the session array of particular product but I can not do this due to product id as a key here is my array

 Array
 (
    [3] => Array
        (
            [product-id] => 3
            [item] => corp
            [unitprice] => 90
            [quantity] => 3
        )

[46] => Array
    (
        [product-id] => 46
        [item] => mike
        [unitprice] => 10
        [quantity] => 1
    )

I've tried using for loop but not working as key does not start form 0,1,2,3 etc. here is my for loop

for($i=0;$i<count($_SESSION['cart']);$i++):
   $_SESSION['cart'][$i]['quantity']=$_REQUEST['qty'.$i.''];
endfor; 
Adi
  • 5,089
  • 6
  • 33
  • 47
Rakhi
  • 929
  • 15
  • 41
  • Please read the manual entry about arrays: http://php.net/manual/en/language.types.array.php – PeeHaa Jun 10 '13 at 08:56

1 Answers1

2

You can use foreach for that. You may refer on this link: php foreach with multidimensional array

Community
  • 1
  • 1
JunM
  • 7,040
  • 7
  • 37
  • 58