Re: [PHP4BETA] Is this a good idea for an operator?
| From: | Adam Trachtenberg | Date: | Wed, 04 Aug 1999 05:12:33 +0000 |
| Subject: | Re: [PHP4BETA] Is this a good idea for an operator? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3092@lists.php.net to get a copy of this message | ||
On Tue, 3 Aug 1999, Dan Wilson wrote:
> function isInArray($value, $ary) {
> for ($i_val = 0; $i_val < count($ary); $i_val++) {
> if ($value == $ary[$i_elem]) {
> return true;
> }
> }
> return false;
> }
I haven't gone so far as to confirm this, since I don't have a don't have
a running copy of PHP4 installed, but have you checked out this function
in the docs?
http://www.php.net/manual/function.in-array.php3
This PHP4 function seems to do exactly what you want -- it returns true if
a value exists in an array. Now, if you wanted to check multiple values,
you'd have to call it twice:
$bar = array('a', 'b', 'c');
if (in_array('a', $bar) && in_array('z', $bar)) {
/* do something */
}
I'd guess it'd be cool if you could pass in an array or a scalar into
in_array() as the needle. If an array was passed, one or all of the
elements would need to be found in the haystack. But, which behavior would
be correct? || or &&?
Honestly, that's not such a big deal to me, since if I'm doing complex
checks to see if elements are living inside sets, I'm usually trying to
foist that heavy lifting off to MySQL, where it will be faster and better.
-adam
--
/ adam maccabee trachtenberg | visit college life online \
\ adam@student.net | http://www.student.com /