Finally, I will talk about a little different path that we need to pay attention to. This means that there are some usage differences between (double quotes) and (single quotes) in PHP. We cannot write a variable in the values that we will give with single quotes, let’s show by example:

<?php
$name = 'Baransel';
$message = 'Hello $name';
echo $message;
?>

The screen displays Hello $name. Because we wrote the variable in single quotes. That’s why it looked at it like a string rather than a variable. If you want to print the $name variable, then you have to do it as in the example in this post.

This event is only valid for single quotes. In double quotes, this situation is different. It writes the values of the variables. That means, we can combine variables in double quotes without using the dot operator. Here comes an example:

<?php
$name = 'Baransel';
$message = "Hello $name";
echo $message;
?>

Note that we used the same as the previous example, but only double quotes, not single quotes in the message variable. And in this case, the screen will say Hello Baransel. Because it returns the values of variables written in double quotes. But this is not the case with a single quotation.

The goal here is to make sure that PHP doesn’t think it’s a variable in some places where we need to use the dollar sign on its own. For example, when we want to print Fee: $100 a on the screen, if we use double quotes, PHP gives an error. Because the dollar sign in double quotes is perceived as special character and variable expression. In these cases, a single quotation or escape operator is used.