1

I am playing around with wordpress and wondering, why this line of code works:

echo "<a href='....'>$name</a>";

I learned it this way:

echo "<a href='....'>".$name."</a>";

Is there something special defined in WP to make this work?

Ben Spi
  • 816
  • 1
  • 11
  • 23
  • Nothing to do with WordPress. Have a look here: http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – StathisG Aug 02 '14 at 16:43

1 Answers1

0

In PHP, there are two types of String.

The first type uses the single quotes, as follows.

$val = 'this is a simple string';

The second type is as follows:

$val = "This is a not so simple string";

With the latter type, any variables included in the string will be resolved to their values, so:

$val = "Hello there";

$message = 'Dave says $val';
// Literally equals: Dave says $val

$message2 = "Dave says $val";
// Literally equals: Dave says Hello there

There are lots of other differences, which you can read about here.

christopher
  • 26,815
  • 5
  • 55
  • 89