-2

This is how I get the date time of a city,

$date = new DateTime('now', new DateTimeZone('Asia/Bangkok'));

instead that need to get it from variables, I tried the below code but it not successful.

$type     = 'Asia';       
$type1     = 'Bangkok';

$date = new DateTime('now', new DateTimeZone('$type/$type1'));

Please help me with this.

Son Truong
  • 13,661
  • 5
  • 32
  • 58
Yasitha
  • 13
  • 7

1 Answers1

-1

You need to use double quotes

  $date = new DateTime('now', new DateTimeZone("$type/$type1"));

for an explanation, I will refer you to this question explaining the difference between '' and "" in PHP.

What is the difference between single-quoted and double-quoted strings in PHP?

mpm
  • 20,148
  • 7
  • 50
  • 55