conditional operator - Compare multiple values in PHP -


i'd go this:

if($var == 3 || $var == 4 || $var == 5 || $var =='string' || $var == '2010-05-16') { execute code here }

to this:

if($var == (3, 4, 5, 'string', '2010-05-16')) {execute code here }

seems redundant keep typing $var, , find makes bit cumbersome read. there way in php simplify in way? read on post here when using xquery can use = operator in $var = (1,2,3,4,5) etc.

thanks, john

place values in array, use function in_array() check if exist.

$checkvars = array(3, 4, 5, "string", "2010-05-16"); if(in_array($var, $checkvars)){     // value found. } 

http://uk.php.net/manual/en/function.in-array.php


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -