Ok. I think I have solved my problem. I used two if-statements to determine if the $_POST variables needed to be reset or not.
PHP Code:
/* this if-statement checks to see if the SESSION variable has been set. if not,
it sets the SESSION variable and stores all of the POST values into the SESSION.
this retains the values, even on refresh, since the variables don't try to reset again
on refresh due to the SESSION variable being set */
<?php
if(!isset($_SESSION['number'])) {
$_SESSION['number'] = 1;
for($i = 1; $i < 6; $i++) {
$_SESSION['storeName'][$i] = $_POST["name$i"];
}
/* the next if-statement only resets the variables if the SESSION variable is set,
and the form passes over a hidden field with hiddenId = 1. without the additional
check for the hiddenId, the variables would never reset, even when a new the form
was submitted with different values */
} else if(isset($_SESSION['number']) && $_POST['hiddenId'] == 1) {
for($i = 1; $i < 6; $i++) {
$_SESSION['storeName'][$i] = $_POST["name$i"];
}
}
?>
<?php for($i = 1; $i < 6; $i++) {
echo "Name ".$i." is ".$_SESSION['storeName'][$i]."<br />";
} ?>