Everything works fine if I don't use this as a function and just place it
inside my code. When I use it as a function it will return the variables
that are in the "else" portion, but not the if statement. I can see the
variables and echo them inside the function, but not outside of it, but just
on the "if" portion, the "else" part is working fine.
I must be missing something here, any help would be appreciated!
function SetSessionVars ($postresults)
{
foreach ($postresults as $key => $val)
{
if (is_array($val))
{
foreach ($val as $subkey => $subval)
{
$prefix = $key . "_";
$newvar = $prefix . $subkey;
$_SESSION['payroll'][$key][$subkey] = $postresults[$key][$subkey];
$$newvar = $_SESSION['payroll'][$key][$subkey];
}
}
else
{
$_SESSION['payroll'][$key] = $postresults[$key];
$$key = $_SESSION['payroll'][$key];
}
}
}