Formatting long if statements in php -


what more decent way format following lines of code. if not format other method do.

if (     array_key_exists('type',$handle) &&     array_key_exists('parent',$handle) &&     array_key_exists('username',$handle) &&     array_key_exists('userid',$handle) &&     array_key_exists('countrycode',$handle) )   if(     ctype_digit($listtype) &&     ctype_digit($listparent) &&      (ctype_alnum($listusername) && (strlen($listusername) >=5 && strlen($listusername) <=24)) &&    ctype_digit($listuserid) &&        (ctype_alpha($listcountrycode) &&     array_key_exists($listcountrycode, $countries))  ) 

also, doable in php?

bool ftest1 = == b ; bool ftest2 = c ; bool ftest3 = f(1,2,3) ; bool fsuccess = ( ftest1 | ftest2 ) & ftest3 ; if ( fsuccess ) ... 

you can use array_intersect , count avoid if clauses.

$arr1 = array("a" => "type", "parent", "username", "userid", "countrycode") $intersect = array_intersect($handle, $arr1) if(count($intersect) == count($arr1)){    //your logic goes here.  } 

also, above "doable" examples valid me.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -