Let's go back to strings.
So we've used the strings throughout the course so far, but we haven't really went deep on them.
So I think it's time that we really dive deeper into strings.
So let's begin with the simplest thing, which is the single and double quote strings.
So there are two types of strings in PHP the single and double quotes.
Here you see the double quote strings.
And what characterizes the double quote strings is that they can interpolate data.
So interpolating essentially means that you can use a variable like name or any expression.
And this would be outputted on the screen like in this example.
So you can also add and use special characters like new line, tab etc..
Now with single quote strings everything inside is treated literally.
So there are no special characters except maybe an escape character and except a single quote ending
character.
Everything else is treated as you would mean a literal string, as in this example.
That would be the output.
So I've already created the strings php file.
You can just grab it from GitHub.
Let's run it so I can do strings.
And we see exactly what I've described.
So with the first example single quotes nothing is actually interpolated.
Everything is treated literally with the second double quote example.
We can clearly see that in place of the name variable here John is outputted as that's the value of
the variable.
Now let's see the different kinds of strings.
So even if you have used PHP before you might not have heard about them.
First is a heredoc syntax.
This is pretty strange.
So we've added those symbols.
You write your code, then end and semicolon.
Now everything between those characters.
The starting and ending lines is actually a multi-line string, so you are free to write multi-line
strings, which wouldn't be really easy.
With single or double quotes, you would have to use a concatenation character, and it would really
be odd to put, uh, those kind of strings into multi-line strings with this heredoc syntax.
This is easy.
Now there are two variants of this.
There is Heredoc and there is another one called now doc.
Now the difference between them is, uh, this actually can have single quotes here.
The difference is pretty simple.
With the here doc you've got interpolation and with now doc you don't.
So those are like single quotes.
And this syntax is like double quotes.
So let's run it.
This is string speech P.
Um yeah I obviously forgot to echo those.
So let me echo here dog and the now dog and let's see this.
So first we've got here dog with interpolation.
Next up we've got now dog without any interpolation.
That's why we see dollar name in here.
So what.
What's the difference.
Why would you have two types of strings.
Well theoretically this single quote string is faster as it has to do less.
It doesn't have to look for variables, for expressions, and for special character combinations like
new lines and tabs.
Just be wary with trying to optimize or do micro-optimizations by always using single quotes first.
Before you do any optimization, just make sure that you profile your code first.
And I think that actually it's rather not possible that the type of strings you use would significantly
improve performance or slow down your application.