我正在构建一个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 ) )
更令人讨厌的是,我确信在调整代码之前我已经正常工作了.我究竟做错了什么?
您也可以使用
原文链接:https://www.f2er.com/php/134923.html+
operator:
$combined = $_SESSION['results'] + $_POST;