PHP $_SESSION replacing

Hi,

I’ve got a $_SESSION array which takes in user information (integer values) but some of the fields can be left blank. So I need to replace the blank elements in the array with zero (i.e. 0) so I can do some more processing.

Hope someone can help :smiley:

John


function replaceWithZeroes($arr)
{
  foreach($arr as $key=>$val)
  {
    if (is_array($val))
    {
       $arr[$key] = replaceWithZeroes($arr[$key]);
    }
    else
    {
       if ($val == '') $arr[$key] = 0;
    }
  }
  return $arr;
}

$_SESSION = replaceWithZeroes($_SESSION);

Is that what you mean?

Why do you want this btw, sounds a bit hacky to me …

Yeah thats what I mean. I’m just tryin to solve a small problem and I know bad practice to hack.

Thank you for your help