0

I have tried for hours to figure this out and it's beaten me. Why does $currentDay return a number representing the day of the week? Can I not assign a variable to the date?

<?php
date_default_timezone_set("America/New_York");
$currentDay = date('l'); // dayname
$currentTime = date("H");
$preOpen = "We're Open";
$preClosed = "We're Closed";
if ($currentDay = "Thursday" && $currentTime >= "22") {
  echo $preClosed."<br>";
} elseif ($currentDay = "Friday") {
  echo $preClosed."<br>";
} elseif ($currentDay = "Saturday" && $currentTime >= "22") {
  echo $preClosed."<br>";
} else {echo $preOpen."<br>";
}
echo date('l')."<br>";
echo $currentDay
?>

1 Answer 1

3

In your if statements, you need to use == to check equality instead of =.

With your current code, when you write ($currentDay = "Thursday" && $currentTime >= "22"), PHP is actually evaluating the value "Thursday" && $currentTime >= "22" as a boolean (which returns 1 right now, after 10 PM in New York) and assigning it to $currentDay.

Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.