0

When I use

echo $stores_open_starts["tuesday"]; or echo $stores_open_starts['tuesday'];

I get

11.00

Now, I want to use this dynamically. I generate the day like this:

$today_date = date('d', strtotime("today")); $today_date = strtolower($today_date);

But then when I do

echo $stores_open_starts["{$today_date}"]; or echo $stores_open_starts[$today_date];

it doesn't work. What am I doing wrong?

7
  • $stores_open_starts["{$today_date}"] means that you want to print an array element with index equals to $today_date value. did your array contains that index? Commented Sep 21, 2016 at 9:01
  • @developer Yes, it contains every day. monday to sunday. Commented Sep 21, 2016 at 9:02
  • Have you tried echo($today_date); to check it's the value you expected? Commented Sep 21, 2016 at 9:03
  • 1
    if you want to use full textual representation of the day of the week you should use l (lower case L) instead of d Commented Sep 21, 2016 at 9:04
  • 1
    Also, don't forget to lowercase your response as date('l') will return Tuesday and it appears you want tuesday. Commented Sep 21, 2016 at 9:06

1 Answer 1

3

I think you want the full day of the week as a string. That's:

$today_date = date('l', strtotime("today"));    //You should use 'l' and not 'd'
$today_date = strtolower($today_date);

'd' returns the day of the month, not the name of the weekday.

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.