Advertisement
Guest User

Untitled

a guest
May 26th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. function alCarrito($id_producto){
  2.  
  3. // Si no hay array con "carrito" creado, crear array dentro de SESSION.
  4. if(!$_SESSION['carrito']){
  5. $_SESSION = array('carrito' => array());
  6. }
  7. // Luego añadimos el valor del id_producto si es que no está puesto ya:
  8. $control = false;
  9. foreach($_SESSION as $clave => $valor){
  10. if($_SESSION[$valor] == $id_producto){
  11. $control = true;
  12. break;
  13. }
  14. }
  15. if($control == false) array_push($_SESSION['carrito'], $id_producto);
  16.  
  17. print_r($_SESSION['carrito']);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement