当前页面.php
//this is required array which you want to enter in session
$array = array(
"product1" => "url1",
"product2" => "url2",
"product3" => "url3"
);
session_start();//here we start a session
$_SESSION['product_url']=$array;//here we pass required array to session
//By the help of below code we check is session contain array
//echo "<pre>";
//print_r($_SESSION);
要求页面.php
session_start();//here we start a session
//finally display required data to reqired page...
foreach($_SESSION['product_url'] as $key=>$value)
{
echo '<a href="'.$value.'">'.$key.'</a><br>';
}
对于多维数组:-
currentpage.php
//this is required multidimensional array which you want to enter in session
$array= array(
"[0]"=>array("product1" => 'url1',"product2" => 'url2',"product3" => 'url3')
);
requieredpage.php
foreach($_SESSION['product_url'] as $key=>$value)
{
foreach($value as $k=>$v){
echo '<a href="'.$v.'">'.$k.'</a><br>';
}
}
我得到的输出:-
product1
product2
product3