Copies of session variables

0

is that I have doubts about how one session variable can be copied to another. I use foreach but it does not work for me. Thank you. I would appreciate it if you answer me soon. Use foreach to make this copy.

foreach ($_SESSION["shopping_cart"] as $keys => $value) 
{   
  foreach ($_SESSION["shopping_cart_copia"] as $key => $value)
  {
   $_SESSION["shopping_cart_copia"][$key]["id_producto"] = 
   $_SESSION["shopping_cart"][$keys]["id_producto"];
   $_SESSION["shopping_cart_copia"][$key]["imagen_producto"] = 
   $_SESSION["shopping_cart"][$keys]["imagen_producto"];
   $_SESSION["shopping_cart_copia"][$key]["nombre_producto"] = 
   $_SESSION["shopping_cart"][$keys]["nombre_producto"];
   $_SESSION["shopping_cart_copia"][$key]["precio_producto"] = 
   $_SESSION["shopping_cart"][$keys]["precio_producto"];
   $_SESSION["shopping_cart_copia"][$key]["cantidad_producto"] = 
   $_SESSION["shopping_cart"][$keys]["cantidad_producto"];
   $_SESSION["shopping_cart_copia"][$key]["stock_oculto"] = 
   $_SESSION["shopping_cart"][$keys]["stock_oculto"];
   }
} 
    
asked by Luisa Perez 28.07.2018 в 15:50
source

2 answers

0

I do not know what you mean, the copy is as simple as

$_SESSION["shopping_cart_copia"] = $_SESSION["shopping_cart"];

With the simple assignment of one variable to the other the value of one is transferred to the other giving a clone of the variable

    
answered by 28.07.2018 / 18:20
source
0

Maybe this could work:

foreach ($_SESSION["shopping_cart"] as $key => $value) 
{   
   $_SESSION["shopping_cart_copia"][$key] = $value
} 

This snippet iterates the entire first session variable by copying the entire array of values to the next session variable.

    
answered by 28.07.2018 в 18:08