syntax - PHP Switch multiple parameters -


is there way of making more organized?

if (!isset( $par2 ) && !isset( $par3 )) {         $where = "lvlone = '".$par1."'";      } elseif(isset( $par2 ) && !isset( $par3 )) {         $where = "lvlone = '".$par1."' , lvltwo = '".$par2."'";      } elseif(isset( $par2 ) && isset( $par3 )) {         $where = "lvlone = '".$par1."' , lvltwo = '".$par2."' , lvlthree = '".$par3."'";     } 

concatenation:

$where = "lvlone = '{$par1}'";  if(isset( $par2 )) {     $where .= " , lvltwo = '{$par2}'"; }  if(isset( $par3 )) {     $where .= " , lvlthree = '{$par3}'"; } 

concatenation ternary:

$where = "lvlone = '{$par1}'"; $where .= isset($par2)?" , lvltwo = '{$par2}'":''; $where .= isset($par3)?" , lvlthree = '{$par3}'":''; 

implode array:

//where 1 nice regardless of number of parameters, //you end proper 'and' between each clause. $where = array("lvlone = '{$par1}'"); if(isset($par2)){     $where[] = "lvltwo = '{$par2}'" } if(isset($par3)){     $where[] = "lvlthree = '{$par3}'" } $where = impode(' , ', $where); 

in end though, if works , isn't holy abomination, daily wtf worthy code, why worry looks like? follow simple syntax structure (ie indented).

edit: changed enclosing variable curly braces because inside of double quotes.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -