I have foreach loop which when looping outputs the items held in an array.This works great, but I want to store a few things per EACH item in session variables so I can use this information elsewhere without page refresh,I am trying to create session variables inside the foreach loop,but of course the variables need to have different data every time it loops through a different item.Suppose in below code i have three different product link,when i click on button how do i get that particular link for that particular product is stored in session variable without reloading a page.When i redirect from one page to other i used that link which is in session variable using session concept.
session.php
<?php
$a=array(
array("Htc 526 black","htc.jpg",23000,"http://www.flipkart.com"),
array("Iphone 6s","apple.jpg",43000,"http://www.amazon.com"),
array("Sony xperia c3 dual","sony.jpg",19000,"http://www.snapdeal.com")
);
foreach($a as $value)
{
session_start();
$_SESSION['link']=$value[3];
?>
<script>
function redirect()
{
window.location="redirection.php";
}
</script>
<button onclick="redirect();">Click Me</button>
<?php
}
?>
redirection.php
<?php
if(session_id()=="")
{
session_start();
}
$deep_link=$_SESSION['link'];
echo $deep_link;?>
My query is when i redirect from one page to other and when i echo the session variable(product link),it only echo's the last value Instead it takes that particular product links