unemployment Posted April 18, 2011 Share Posted April 18, 2011 Is this proper syntax? if (($news['accounttyperaw'] !== 0) || ($news['accounttyperaw'] !== 1)) Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/ Share on other sites More sharing options...
Maq Posted April 18, 2011 Share Posted April 18, 2011 Syntax is correct, but the logic doesn't make sense. Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203151 Share on other sites More sharing options...
unemployment Posted April 18, 2011 Author Share Posted April 18, 2011 I'm basically just trying to say if accounttyperaw is not equal to zero or 1 do something Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203154 Share on other sites More sharing options...
Maq Posted April 18, 2011 Share Posted April 18, 2011 I'm basically just trying to say if accounttyperaw is not equal to zero or 1 do something I think you want to use &&. If $news['accounttyperaw'] is 0, then the second condition is true, if $news['accounttyperaw'] is 1, then the first condition is true, if $news['accounttyperaw'] is neither 0 or 1, then they are both true. So your IF block will always result in TRUE. Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203159 Share on other sites More sharing options...
maxudaskin Posted April 18, 2011 Share Posted April 18, 2011 I'm basically just trying to say if accounttyperaw is not equal to zero or 1 do something Using your words directly, it should do what you want, although, you don't need those extra set of parenthesis around each clause. <?php if (($news['accounttyperaw'] !== 0) || ($news['accounttyperaw'] !== 1)) // Can be: if ($news['accounttyperaw'] !== 0 || $news['accounttyperaw'] !== 1) If you want to do two different things for each clause, I would do: <?php if ($news['accounttyperaw'] !== 0) { // do something } else { if($news['accounttyperaw'] !== 1) { // do something else } } Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203222 Share on other sites More sharing options...
kansasakki Posted April 18, 2011 Share Posted April 18, 2011 $a != $b Not equal TRUE if $a is not equal to $b after type juggling. <?php if (($news['accounttyperaw'] !== 0) || ($news['accounttyperaw'] !== 1)) // Can be: if ($news['accounttyperaw'] !== 0 || $news['accounttyperaw'] !== 1) ] should be != with one 'equal' sign i think <?php if (($news['accounttyperaw'] != 0) || ($news['accounttyperaw'] !== 1)) // Can be: if ($news['accounttyperaw'] != 0 || $news['accounttyperaw'] !== 1) ] Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203237 Share on other sites More sharing options...
maxudaskin Posted April 18, 2011 Share Posted April 18, 2011 He chose to use a strict comparison, so I left it there. Really, unless it outputs some of the values as a string (1 vs '1'), then it should be fine. Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203240 Share on other sites More sharing options...
Stooney Posted April 18, 2011 Share Posted April 18, 2011 some other ideas <?php if(!in_array(intval($news['accounttyperaw']), array(0, 1))){ //does not equal 0 or 1 } or <?php if(intval($news['accounttyperaw'])>1){ //Does not equal 0 or 1 } Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203242 Share on other sites More sharing options...
Pikachu2000 Posted April 18, 2011 Share Posted April 18, 2011 What you need to use is this: if( $news['accounttyperaw'] !== 0) && $news['accounttyperaw'] !== 1 ) { Link to comment https://forums.phpfreaks.com/topic/234086-if-syntax/#findComment-1203253 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.