Array and if-else statement issue
I have two forms, if $_POST['submit']
of the first form is click the second form is loaded and an array is assigned with $POST data of first form , else if the $_POST['submit']
of the second form is pressed the same array needs to have additional elements this time from $POST of second form, but the problem is that my array is getting empty as soon as the elseif
is executed. I tried passing the array by reference but that did not help me.
if(isset(btn_Of_Form1)) {
echo "form2"; $my_arr =$_POST;
}
elseif(btn_of_Form2){
$my_arr =array_merge($my_arr,$_POST);
开发者_运维知识库}
You can use $_SESSION
and serialize
:
session_start();
if(isset(btn_Of_Form1))
{
echo "form2";
$_SESSION['data'] = serialize($_POST);
}
elseif(btn_of_Form2)
{
$my_arr = unserialize($_SESSION['data']);
$my_arr = array_merge($my_arr,$_POST);
}
精彩评论