Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wildiney/5688833 to your computer and use it in GitHub Desktop.

Select an option

Save wildiney/5688833 to your computer and use it in GitHub Desktop.
Automatically creates variables with the same name as the key in the POST array
<?php
$username=$_POST["username"];
$age=$_POST["age"];
etc.
?>
<?php
$expected=array('username','age','city','street');
foreach($expected as $key){
if(!empty($_POST[$key])){
${key}=$_POST[$key];
}
else{
${key}=NULL;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment