Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/05/2008, 16:17
Avatar de da2
da2
 
Fecha de Ingreso: abril-2003
Ubicación: Catalunya
Mensajes: 239
Antigüedad: 21 años
Puntos: 0
asignar valor a un array en carrito webestilo

Hola a todos,
lo que voy a preguntar lo habia preguntado en otro post abierto pero algun moderador a cerrado el post y ha borrado mi pregunta y la respuesta que me habian dado. (No se por que!)

Bien este es el carrito de WEBESTUDIO

<?php // Manual de PHP de WebEstilo.com
session_start();
session_register('itemsEnCesta');
$item=$_POST['item'];
$cantidad=$_POST['cantidad'];
$itemsEnCesta=$_SESSION['itemsEnCesta'];

if ($item){
if (!isset($itemsEnCesta)){
$itemsEnCesta[$item]=$cantidad;
}else{
foreach($itemsEnCesta as $k => $v){
if ($item==$k){
$itemsEnCesta[$k]+=$cantidad;
$encontrado=1;
}
}
if (!$encontrado) $itemsEnCesta[$item]=$cantidad;
}
}
$_SESSION['itemsEnCesta']=$itemsEnCesta;
?>
<html>
<body>
<tt>
<form action="<?=$PHP_SELF."?".$SID?>" method="post">
Dime el producto <input type="text" name="item" size="20"><br>
Cuantas unidades <input type="text" name="cantidad" size="20"><br>
<input type="submit" value="Añadir a la cesta"><br>
</form>
<?
if (isset($itemsEnCesta)){
echo'El contenido de la cesta de la compra es:<br>';
foreach($itemsEnCesta as $k => $v){
echo 'Artículo: '.$k.' ud: '.$v.'<br>';
}
}
?>
</tt>
</body>
</html>



En la expresión $k => $v
$K parece ser el indice per y $ el valor, Pero donde esta el valor de $v. Aguien melo podria explicar

Gracias por vuestra paciencia.