Quotes and the differences

Using Quotes in PHP

//Single quotes will be demonstrated first

singles

Example 1: Single Quotes

Hello, my name is $name.
//doubles will now be here

Doubles

Example 2: Double Quotes

Hello, my name is Ben.

The difference between the two

In PHP, single quotes and double quotes work differently. When you use single quotes, PHP treats the content as a literal string, so variables are not interpreted. For example, in single quotes, 'Hello, my name is $name.' will display exactly as it is, without replacing $name with its value.
However, with double quotes, PHP will replace variables inside the string. For example, "Hello, my name is $name." will display "Hello, my name is Ben.".

Go Back