Jump to content

If Syntax


unemployment

Recommended Posts

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

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

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.