Re: Testing if any of the items are false

From: Date: Mon, 10 Feb 2003 21:19:41 +0000
Subject: Re: Testing if any of the items are false
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-135115@lists.php.net to get a copy of this message
--- rdkurth@starband.net wrote: > How can I do this to determine if one of the items is > false if none are then I what it to print the first > echo of there is one that is false then print the > second echo Sorry, that makes no sense to me. > $test1= "YES"; > $test2= "YES"; > $test3= "YES"; > $test4= "YES"; > $ftest1= "YES"; > $ftest2= "NO"; > $ftest3= "YES"; > $ftest4= "YES"; > > if > ($test1==$ftest1)or($test2==$ftest2)or($test3==$ftest3) > or($test4==$ftest4){ > echo "all of the items are true"; > }else{ > echo "one of the items is false"; > } That code makes less sense. Are you wanting to see if each of your $test variables match their corresponding $ftest variable? Your current statement is true when any of the $test variables match their corresponding $ftest variable. Try using "and" instead of "or" if you want to require them all to be true. Just read it aloud, and it should make sense. if ($flavor == 'vanilla' || $flavor == 'chocolate') { eat('ice_cream'); } In this example, you would eat the ice cream if it was vanilla *or* chocolate. Chris

« previous php.general (#135115) next »