Alternate Post Request Acceptance

Hello, I have a form with 4 fields, in the handler I process them like this

if (isset($_POST['name'])) {$name= $_POST['name']; if ($name == '') {unset($name);}}  
if (isset($_POST['id'])) {$id= $_POST['id']; if ($id== '') {unset($id);}}  
if (isset($_POST['text'])) {$text= $_POST['text']; if ($text== '') {unset($text);}}  
if (isset($_POST['description'])) {$description= $_POST['description']; if ($description== '') {unset($description);}}

And it turns out to be a very large code, is there any way to accept Post requests differently?
And then there may be more requests.


Answer 1, authority 100%

function gv (&$v, $alt = false) { return (!empty($v)) ? $v : $alt; }
$err = 0;
foreach (array('name', 'id', 'text', 'description') as $v)
  if (!$$v = gv($_POST[$v])) $err++;

Answer 2, authority 50%

You can. For example:

$varnames = array('name','id','text','description');  
foreach($varnames as $varname){  
  if(!empty($_POST[$varname])){//   ,    .         ,     
    $$varname = $_POST[$varname]; //      
  }  
}

P.S. if this piece of code is somewhere in the middle and there is no certainty that the specified variables were not created earlier, you can slightly change the loop:

foreach($varnames as $varname){  
      if(isset($$varname)) unset($$varname);
      if(!empty($......

Answer 3

I think it could be even shorter. You can try using

foreach($_POST as $key=>$value) { if($value!='') $key=$value; }

Answer 4

You can do this

$arr=array();
$result=array();
$arr=$_POST;
foreach ($arr as $key => $value) {
   $result[$key] = $value;
}

and then process the $result array