php - $_POST better writing quality -


i have code :

if(isset($_post['prenom2'])){     $t['prenom2'] = $_post['prenom2']; }else{     $t['prenom2'] = ''; }  if(isset($_post['nom2'])){     $t['nom2'] = $_post['nom2']; }else{     $t['nom2'] = ''; }  if(isset($_post['prenom3'])){     $t['prenom3'] = $_post['prenom3']; }else{     $t['prenom3'] = ''; } 

etc (there 5 or 6 fields need test).

there must better way of doing this, if given index of post isn't set, index is...

thanks

based on real problem, may choose 1 of these:

 for($i=1; $i<6; $i++){      $t['prenom'.$i] = (isset($_post['prenom'.$i])) ? $_post['prenom'.$i] : '';      $t['nom'.$i] = (isset($_post['nom'.$i])) ? $_post['nom'.$i] : '';   }         

or

 $indexes = array('prenom2'=>'', 'nom2'=>'', ...);  $t = array_merge($indexes,$_post); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -