Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this function takes an array of strings
- //for every string it checks if a variable with that name is set in $_POST $_GET or in $GLOBALS (so at all)
- //if it is not set it is created as '' and put into an array
- //that array is returned
- function ifNotSetMakeEmpty($vars)
- {
- $setVars = array();
- foreach($vars as $key => $value)
- {
- //now we check if the given vars are set
- //if it is set, assign it to the array that will be returned
- if(isset($GLOBALS[$value]))//check if a global var with that name is set
- {
- $setVars[$value]=$GLOBALS[$value];
- }
- else if(isset($_POST[$value]))
- {
- $setVars[$value]=$_POST[$value];
- }
- else if(isset($_GET[$value]))
- {
- $setVars[$value]=$_GET[$value];
- }
- else
- {
- $setVars[$value]='';
- }
- }
- return $setVars;
- }
- //get variables
- extract(ifNotSetMakeEmpty(array('foo','bar')));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement