Jump to content

If statement running when it shouldn't


bschultz

Recommended Posts

The following code ran as true on Friday at 11:45pm...and $showname did not equal anything...anyone know why?

 

if ((($dow != 'Friday' || $dow != 'Saturday') && $hour == '23' && $minute == '45') || $showname == 'livingthecountrylife')

 

This should only run on Sunday, MOnday, Tuesday, Wednesday and Thursday night at 11:45pm...or when run from command line passing the variable Showname the value of livingthecountrylife.

 

The date and time variables are set like this:

 

$year = date('Y'); // 4 digit
$month = date('m'); // with leading zeros
$date = date('d'); // with leading zeros
$dow = date('l'); // Sunday Monday Tuesday...etc
$hour = date('H'); // 24 hour with leading zeros
$minute = date('i'); // with leading zero
$now = date('Y-m-d');

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/279206-if-statement-running-when-it-shouldnt/
Share on other sites

because you are using negative logic, you must complement the conditional test OR you could use true logic and complement that expression. either of the following should work (untested) -

 

if ((($dow != 'Friday' && $dow != 'Saturday') && $hour == '23' && $minute == '45') || $showname == 'livingthecountrylife')

 

if ((!($dow == 'Friday' || $dow == 'Saturday') && $hour == '23' && $minute == '45') || $showname == 'livingthecountrylife')

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.