SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Location
    Ireland
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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

    John

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,096
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    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 ...
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Location
    Ireland
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •