Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    Unsetting Variables

    Hello all,

    I have borrowed a function from PHP.net user notes. It cycles through alll the variables in a PHP program and prints them all. See below.

    PHP Code:
    function getDefinedVars($varList$excludeList)
      {
          
    $temp1 array_values(array_diff(array_keys($varList), $excludeList));
          
    $temp2 = array();
          while (list(
    $key$value) = each($temp1)) {
              global $
    $value;
              
    $temp2[$value] = $$value;
                }
          return 
    $temp2;
      } 
    The excludeList variable is an array contraining several variables that are not listed such as _ENV and so forth.

    I have been attempting to add to this so that it lists the variables and then right after, it unsets all of them. Eqauting in unsetting all the variables in an instance of PHP. I have tried to UNSET the global variable variable during the while loop, however with no success. No errors, however variables remain set.
    PHP Code:
    function getDefinedVars($varList$excludeList)
      {
          
    $temp1 array_values(array_diff(array_keys($varList), $excludeList));
          
    $temp2 = array();
          while (list(
    $key$value) = each($temp1)) {
              global $
    $value;
              
    $temp2[$value] = $$value;
              
           unset(
    $GLOBALS[$$value]);   //added unset here
           
          
    }
          return 
    $temp2;
      } 
    Does anyone have any pointers or ideas here? Your assistance is much appercated.
    Warm Regards,
    Sir P

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    No idea here?

    Cheers very much


  •  

    Posting Permissions

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