PHP Variables and its checking for null with some discipline -


i want hints php

here variables

$error; $a=$_post["sdf"]; $b=$_post["dsf"]; $c=$_post["ssdfsdfdf"]; $d=$_post["ssdfsddf"]; $e=$_post["sdfsdfdf"]; $f=$_post["sfsdfsdf"]; $g=$_post["sdsdff"]; $g=$_post["sdsdfsdff"]; 

i want check whether variables empty or not , dispaly message this

if(empty($a)){ $error.="hey missed $a "; // $a value } 

now have repeat codes ...

imagine have more 40 variables can hints short code

i tried switch statement it's not working ..i want display error message of variable missing...

regards

$required = ["sdf", "dsf", "ssdfsdfdf"]; //etc. etc. $arr = []; //loop through , santize input.  foreach($_post $key => $value) {     //sanitize input here      //store in array     $arr[$key] = $value;  }  //check empty foreach($arr $key => $value) {     if(in_array($key, $required)     {        if(empty($value))        {             throw new exception("one of required attributes empty");         }     } } 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -