the double quotes are parsed by php to find where there is any variable that needs to be displayed e.g
$w = "world";
echo " Hello $w"; // taken as Hello World
echo 'Hello $w'; // taken as Hello $w
Sometimes people use double quotes in PHP to avoid having to use the period to separate code. For example, you could write:
$color='blue';
echo "I have a $color shirt on today";
It was faster and easier but is not better.
A better way to write this code would be:
echo 'I have a ' .$color. ' shirt on today';
Although it is produce the same output. But phrasing your code in the second method will result in less chance of error messages, or problems with other programmers deciphering your code.
No comments:
Post a Comment