Advertisement
Guest User

Niels Bom

a guest
Jun 14th, 2009
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. //this function takes an array of strings
  2. //for every string it checks if a variable with that name is set in $_POST $_GET or in $GLOBALS (so at all)
  3. //if it is not set it is created as '' and put into an array
  4. //that array is returned
  5. function ifNotSetMakeEmpty($vars)
  6. {
  7.     $setVars = array();
  8.     foreach($vars as $key => $value)
  9.     {
  10.         //now we check if the given vars are set
  11.         //if it is set, assign it to the array that will be returned
  12.         if(isset($GLOBALS[$value]))//check if a global var with that name is set
  13.         {
  14.             $setVars[$value]=$GLOBALS[$value];
  15.         }
  16.         else if(isset($_POST[$value]))
  17.         {
  18.             $setVars[$value]=$_POST[$value];
  19.         }
  20.         else if(isset($_GET[$value]))
  21.         {
  22.             $setVars[$value]=$_GET[$value];
  23.         }
  24.         else
  25.         {
  26.             $setVars[$value]='';
  27.         }
  28.     }
  29.     return $setVars;
  30. }
  31.  
  32.  
  33. //get variables
  34. extract(ifNotSetMakeEmpty(array('foo','bar')));
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement