php - How to shorten `if-statement` -
i have if statement in foreach loop. condition 125 characters long. there other ways shorten this?
if ($col == 'foo' || $col == 'bar' || $col == 'baz' || $col == 'fubar' || $col == 'spam' || $col == 'eggs') { continue; } note: sorry confusion on condition values guys, 'a', 'b', ... meant various strings.
store elements in single dimension array first, in case like:
$array = array('a','b','c','d','e','f'); then use php in built function in_array() check whether $col exists in array, in looks like:
in_array($col, $array); entire code:
$array = array('a','b','c','d','e','f'); if(in_array($col, $array)) { continue; }
Comments
Post a Comment