yoda699 Posted November 24, 2009 Share Posted November 24, 2009 Hi, I am trying to create an IF statement with several conditions. What I am trying to achieve is actually three conditions: 1. $num_errors > 0 2. And $field != "curpass" 3. Or $field != "newpass" I wrote the statement using AND (&&) + OR (||) operators in the same statement, but it doesn't work. Could please look at my code and tell me whats wrong. Is it even possible to do what I am trying to do? Thanks ahead, if ($this->num_errors > 0 && $field != "curpass" || $field != "newpass"){ return "<img src=\"../images/check.jpg\" alt=\"\" width=\"34\" height=\"34\" />"; //Errors with form } else{ return ""; Link to comment https://forums.phpfreaks.com/topic/182747-if-statment-with-several-conditions/ Share on other sites More sharing options...
priti Posted November 24, 2009 Share Posted November 24, 2009 Try ($this->num_errors > 0 && ($field != "curpass" || $field != "newpass")) OR $arrValidField=array("curpass","newpass") ($this->num_errors > 0 && !in_array($field,$arrValidField)) Link to comment https://forums.phpfreaks.com/topic/182747-if-statment-with-several-conditions/#findComment-964549 Share on other sites More sharing options...
yoda699 Posted November 24, 2009 Author Share Posted November 24, 2009 Thanks very much. The first option worked great for me. Link to comment https://forums.phpfreaks.com/topic/182747-if-statment-with-several-conditions/#findComment-964552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.