|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-03-22 13:11 UTC] amin dot javanbakht at openwave dot com
if ( ( $name != "test1" ) || ( $name != "test2" ) ) does not work properly. if I Do each condition seperately, it works but If I join them using || then this never works however this works fine if ( ( $name == "test1" ) || ( $name == "test2" ) ) it seems like the problem occurs only with "!=" condition PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 02:00:01 2025 UTC |
What is $name supposed to be? Your examples (!= or ==) are applying a completely different logic. $name = "foo"; If $name is not "test1" => TRUE This Condition breaks at this point. The second condition is never executed. Consider the following Script: ------------------------------------------- <?php function first() { echo "first<br>\n"; return true; } function second() { echo "second<br>\n"; return true; } if(first() || second()) echo "YES<br>\n"; else echo "NO<br>\n"; ?> ------------------------------------------- The output is NOT "first, second, YES" as you might think. It is "first, YES". The || operator checks whether either the left condition or the right condition returns true. If the left condition is true, the right condition is not anymore checked. Daniel Lorch