Accumulating $_POST

I thought this code would allow me to accumulate separate $_POST inputs, but it won’t cycle on the first condition. Any ideas? Is there a better way to test for whether an array is set?

if (isset($curacc2)) {
  echo "here1";
  $curacc2 = array_merge($curacc2,$_POST);
} else {
  echo "here2";
  $curacc2 = $_POST;
echo var_dump($curacc2) . '<br/>';

What do you see if you


before the if statement?

Notice: Undefined variable: curacc2 in E:\wamp\www\dashboard2.php on line 19

What do you mean by it won’t cycle? Is this in a loop? Maybe you could post more code and provide some output?

$curacc2 is not set, so the first condition is never met, meaning $curacc2 just gets a copy of $_POST placed in it.

isseet() should be fine, though depending on the values that it could be set to previously you could use is_array() to make sure it’s set and is of type array.

went with:

if (!isset($_SESSION['post'])) {
            $_SESSION['post'] = array();
          } else {
		    $_SESSION['post'] = array_merge($_SESSION['post'], $_POST);
            $_SESSION['post'] = array_values($_SESSION['post']);			

Thanks to LeonardChallis for your help.