$age = 22;
And I wanted to use it in an echo statement I could do this with single quotes:
echo ‘I am ‘ . $age . ‘ years old’;
That would work fine, it would print out to the page “I am 22 years old” just like expected. There is nothing wrong with that except we have to use concatenation (adding strings together) by adding the periods. The useful part about double quotes in PHP is you don’t have to use concatenation, you just insert the variable inside the string like so:
echo “I am $age years old”;
This would print out to the page “I am 22 years old” and it was a lot easier to type out and read without using the concatenation periods. If you’d like to learn more, be sure to check out our web design/development trainings. Have an amazing day!