Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function alCarrito($id_producto){
- // Si no hay array con "carrito" creado, crear array dentro de SESSION.
- if(!$_SESSION['carrito']){
- $_SESSION = array('carrito' => array());
- }
- // Luego añadimos el valor del id_producto si es que no está puesto ya:
- $control = false;
- foreach($_SESSION as $clave => $valor){
- if($_SESSION[$valor] == $id_producto){
- $control = true;
- break;
- }
- }
- if($control == false) array_push($_SESSION['carrito'], $id_producto);
- print_r($_SESSION['carrito']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement