how to make a for loop with a bi-dimensional array in PHP?

0

I have 2 variables that come by get method

 if(isset($_GET['p'])){
  $_SESSION['producto']['id'] = $_GET['p']; 
  }

 if(isset($_GET['c'])){
 $_SESSION['producto']['can'] = $_GET['c']; 
 }

with that I need to make a foreach loop that travels the bi-dimensional array and then make a query query and put the query data with while

for ($i=0; $i < count($_SESSION['producto']); $i+=2 ){

 $query = mysqli_query($conect,'SELECT * FROM Productos WHERE 
 id='.$_SESSION['producto']['id'].''); //no pongo mas para no aburrir

the thing esque cone so I throw the result well but if I keep clicking on add cart no longer executes the code no s esi no longer runs the loop just change information as I click if I have 1 and I return to click on instead of increasing another line to that 1 changes it to 2 and nothing else

    
asked by Vinicio Moya Almeida 25.10.2017 в 06:59
source

1 answer

0

I can not fully understand the whole problem, since you say that you want the whole array to be traversed, but the for loop increases it by 2 in 2. But what I can see is that you do not use the for loop . The for loop can not increase like this: i+=2 .

If you want the variable i to increase one by one, it would be like this:

for ($i=0; $i < count($_SESSION['producto']); $i++ ){

But if you really wanted it to increase from 2 to 2, the sentence you show is also incorrect. It should be done like this:

for ($i=0; $i < count($_SESSION['producto']); $i+2 ){
    
answered by 25.10.2017 в 08:41