我正在从产品页面传递数组,并使用$ _GET [' id']将产品ID存储在' id'然后将其存储在会话[' items']中。
在购物车页面上,我想只回显一下' id'数组的元素而不是数量。但我仍然想保持当前代码$ item和$ value是echo。
添加到cart.php
**code
session_start();
$_SESSION['items'][]=array(
'id'=>"'".$_GET['id']."'",
'qty'=> 1
);
?>
Cart.php
**code
<?php
session_start();
foreach($_SESSION['items'] as $items=>$values)
{
foreach($values as $item=>$value)
{
//// I want to keep this,
echo $item;
echo $value."<br/>";
echo "</br>";
//// I want to keep this
//// echo 'id' values here!
}
}
?>
答案 0 :(得分:1)
您需要echo $value['id'];
<?php
session_start();
foreach($_SESSION['items'] as $items=>$values)
{
foreach($values as $item=>$value)
{
//// I want to keep this,
echo $item;
echo $value."<br/>";
echo "</br>";
//// I want to keep this
echo $value['id'];
}
}
?>