Eai rapazeada!
I'm doing a prototype ordering system.
My idea: I have a list of products and when the user clicks on the more or less of the item, I call a javascript function to change the quantity of the product and it calls via ajax a php routine that adjusts the quantity of the requested items in a session .
My problem is that I can not change the value of the second position of the two-dimensional array. I've already asked apache to show me the value of the position and it shows, but if I need to add one or subtract one but it does not change the original value.
error_reporting(E_ALL);
session_start();
//unset($_SESSION['ItensPedido']);
//$codProd = $_GET['cod'];
//$conta = $_GET['conta'];
//$existe = 0;
$codProd = 20;
$conta = 1;
$existe = 0;
if(!isset($_SESSION['ItensPedido'])){
$_SESSION['ItensPedido'] = array();
array_push($_SESSION['ItensPedido'], array($codProd,1));
}else{
foreach($_SESSION['ItensPedido'] as $item){
if($item[0] == $codProd){
if($conta == 1){
$item[1] = $item[1] + 1;
echo "<pre>", print_r($item, true),"</pre>";
}else{
if($item[1] != 0){
$item[1]--;
}else{
unset($item);
}
}
$existe++;
}
}
if($existe == 0){
array_push($_SESSION['ItensPedido'], array($codProd,1));
}
}
echo "<pre>", print_r($_SESSION['ItensPedido'], true),"</pre>";