我正在构建一个 3 页的提交表单,我非常希望将所有 $_POST 结果存储在单个会话变量中。
因此,第 1 页首先设置数组并添加第一批发布数据:
$_SESSION['results'] = array();
$_SESSION['results'] = $_POST // first lot of post data
这很好用并返回一个数组,如:
Array
(
[name] => bob
[address] => 1 foobar way
[age] => 100
)
因此,当我从第 2 页获得结果时,我只想将它们附加到现有数组而不调用新数组+键
array_push($_SESSION['results'], $_POST); //second lot of post data
要得到这样的东西:
Array
(
[name] => bob
[address] => 1 foobar way
[age] => 100
[job] => rubbish php dev
[salary] => 1000
)
但相反,我得到:
Array
(
[name] => bob
[address] => 1 foobar way
[age] => 100
[0] => Array
(
[job] => rubbish php dev
[salary] => 1000
)
)
更烦人的是,我确信在我调整代码之前我已经正常工作了。我究竟做错了什么?