我只想在数组中添加会话值,但它只显示最后一个元素。这是我的代码
if(isset($_SESSION["cart_products"])) {
foreach ($_SESSION["cart_products"] as $cart_item)
{
$p_name = $cart_item["info2"];
}
echo $p_name;
}
$product_files[] = array(
'name' => $p_name,
'filename' => $p_name,
'source'=> $c_path );
答案 0 :(得分:1)
您可以执行以下操作
if(isset($_SESSION["cart_products"])) {
$args = array();
foreach ($_SESSION["cart_products"] as $cart_item){
$args[] = $cart_item["info2"];
}
print_r($args);
答案 1 :(得分:0)
<强>更新强>
if(isset($_SESSION["cart_products"])) {
$p_name = array();
foreach ($_SESSION["cart_products"] as $cart_item)
{
$p_name = $cart_item["info2"];
$product_files[] = array(
'name' => $p_name ,
'filename' => $p_name,
'source'=> $c_path);
}
}
更新了圈内的$ product_files