Check a variable in an array in PHP

It seems to me that I should use in_array () , but for some reason it gives me inaccurate information. I looked through array_search () and array_key_exists () , but it seems like this is only useful if I have a key and a value in my array that I am not doing. In a nutshell Im working condition to get the current time and day of EST and determine whether it is "within hours" or "after a few hours."

So, on Tuesday at 19:00 it should say "After an hour," but it repeats, "At hours," am I missing something?

Code example:

<?php

date_default_timezone_set('US/Eastern');
$current_time = date('A'); //AM or PM
$current_day = date('l'); // Sunday - Saturday
$current_hour = date('H'); // 08 / 24hr Time Format

$closed_days = array('Saturday','Sunday');

$closed_hours = array('17','18','19','20','21','22','23','00','01','02','03','04','05','06','07','08');
?>
<?php
echo $current_time . '<br />';
echo $current_day . '<br />';
echo $current_hour . '<br />';
//Operating Hours
if(!in_array($current_day, $closed_days) || !in_array($current_hour, $closed_hours)) {
    echo 'During Hours';
} else { 
    echo 'After Hours';
} ?>

Returns:

PM
Tuesday
19
During Hours
+4
source share
3 answers

Edit:

if(!in_array($current_day, $closed_days) || !in_array($current_hour, $closed_hours)) {

to

if(!in_array($current_day, $closed_days) && !in_array($current_hour, $closed_hours)) {

|| "", , , ,

&& equally to "and", ,

+6

, , if :

!in_array($current_day, $closed_days) || !in_array($current_hour, $closed_hours)

To:

!in_array($current_day, $closed_days) && !in_array($current_hour, $closed_hours)

OR, , 1

+1

Edit

if(!in_array($current_day, $closed_days) || !in_array($current_hour, $closed_hours)) {
  echo 'During Hours';
} else { 
     echo 'After Hours';
} 

to

if(in_array($current_day, $closed_days) || in_array($current_hour, $closed_hours)){
  echo 'After Hours';
}
else{
   echo 'During Hours';
}
-1
source

All Articles