> -----Original Message----- > From: Lazor, Ed [mailto:[EMAIL PROTECTED]] > Sent: 17 June 2002 21:24 > To: 'Chris Knipe'; [EMAIL PROTECTED] > Subject: RE: [PHP] substr? > > > Here's another way of writing that code that may be easier to > work with: > > $TestValues = array("072", "073", "082", "083", "084"); > $NumC = $substr($_POST['NumC'], 0, 3); > if (in_array($NumC, $TestValues)) > $FormError = "True";
And here's another: switch substr($_POST'NumC'], 0, 3): case '072': case '073': case '082': case '083': case '084': // acceptable -- do anything appropriate here // (even nothing, if that's what you want!) break; default: // not acceptable $FormError = "True"; endswitch; Incidentally, why are you setting the variable $FormError to the string "True", rather than the Boolean TRUE? You may have a perfectly ggod reason, but it looks odd to my eyes. If a Boolean would be acceptable, you could also write it like this: $NumC = substr($_POST'NumC'], 0, 3); $FormError = $NumC!='072' && $NumC!='073' && $NumC!='082' && $NumC!='083' && $NumC!='084'; or: $FormError = !in_array(substr($_POST'NumC'], 0, 3), array('072', '073', '082', '083', '084')); > > -----Original Message----- > > From: Chris Knipe [mailto:[EMAIL PROTECTED]] > > Sent: Monday, June 17, 2002 12:19 PM > > > > So what's the difference between > > if (!(($blah == blah) OR ($ab == ab))) { > > and > > if ((!$blah == blah) OR (!$ab == ab)) { Well, as you've written it, a hell of a lot!! I assume you meant the second version to be: if (!($blah == blah) OR !($ab == ab)) { > > Shouldn't they both do the same? And if so, why didn't they > > in this case?? No, they absolutely shouldn't. Think about it: the first ORs the two comparisons, and then takes the NOT of that; the second NOTs both comparisoons, then does the OR. It's the same sort of reason why $x = -1 * -2; is not the same as $x = -(1 * 2); When working with Boolean expressions in this way, deMorgan's laws often come in handy; these state that: !a AND !b is the same as !(a OR b) !a OR !b is the same as !(a AND b) Hope this helps!! Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php