Re: Suggestion for "IN()"

From: Date: Wed, 06 Oct 2004 21:22:36 +0000
Subject: Re: Suggestion for "IN()"
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198784@lists.php.net to get a copy of this message
Your first scenario can been done in a similar fashion to how you are used to doing it in SQL: if ( in_array($a, array(1,4,20,...) ) {} Your second scenario doesn't seem like there is much of a problem because it will always be short (can only have 2 comparisons). -Shawn Jay Blanchard wrote:
[snip] I'm sure I'll be flamed for this, but it seems to me that there should be a shortcut way to write: If ($a == 1 || $a == 4 || $a == 20 || ...) {} To something more like what SQL has... If ( $a IN(1,4,20,...) ) {} And same with the very helpful SQL BETWEEN 'function'. Instead of If ($a > 1 && $a < 20) {} Why not If ($a BETWEEN (1,20)) {} [/snip] You could write a function and share it with the rest of us!


« previous php.general (#198784) next »