Items are doubled in an array in session

Shawnturner
Posts: 2

Items are doubled in an array in session

Hello,

I have two files: File1: choice.php and File2: summary.php. The members of my sportclub may choose material in file 1 and see the summary in file2.
The members may switch as many times as they want from file 1 to file 2. The purpose is to see an extra line in the summary after each choice.
In File1 I have this:

Code: Select all

$_SESSION['summorder'][] = "my hardcoded text ".$myvar;
and in File2 this:

Code: Select all

echo implode("",$_SESSION['summorder']);
The results are not what I expect:
After choice1 the following lines are visible
Line 1 is empty (no data, only hardcoded text)
Line 2 correspond to the choice made.
After choice2:
Line 2 is doubled and line 3 (corresponding to choice 2) is visible.
And so on after every choice, previous line doubled, latest choice correct.

Any idea what is going wrong?

Thank you for your help.

Admin
Try to remove the duplicate values from that session array:

Code: Select all

$_SESSION['summorder'][] = "my hardcoded text ".$myvar; $_SESSION['summorder'] = array_unique($_SESSION['summorder']);

Similar Topics