如何将变量添加到$_SESSION
?
$product = 0;
$_SESSION['product_number'.$product.''] = true;
它不工作。
你需要确保你使用了session_start();
<?php
session_start();
$product = 0;
$_SESSION['product_number'.$product] = true;
?>
<?php
session_start();
$product = 0;
if ($_SESSION['product_number'.$product]) echo 'Session variable was set!';
else echo 'It was not!';
?>
这可能对您有用:
<?
session_start();
$product = 0;
$_SESSION['product_number'] = $product;
?>