Sometimes some basic thing in PHP confuses us a Lot e.g difference between double quotes and single quotes , difference between echo and print etc. Although when we use these on one another place then everything works fine but there is some basic difference between the working of those. so today we going to understand some such type of basic things in PHP.
Single Quotes and Double Quotes
Single quotes will just put exactly what is inside it single quotes can never sense any variable in its scope but Double quotes will evaluate first what is given in it. e.g.
But if we use it for a simple string then output will be same in both cases and also the biggest difference between both it their processing speed. Single quotes are much faster that double quotes. its quite difficult to see in small programs. if you got a 1500 times a loop then you can easily see the difference.
echo and print
Echo and print both are use to output the information on user's screen but the difference is that print can return true or false means its useful if we want to use it in loop but echo is different it doesn't returns any value that's why it is faster than print otherwise the use of echo and print is save.
Use Nested Quotes
if you want to use Quotes inside the quotes means double quotes inside double quotes then you have to 'escape' them eg
this is not gonna work because when it will show an error to use nested quotes you have to escape them with backslash (\). you can do that in following manner.
the above given code will work fine. So these were some basic thing about PHP for beginners hope this will help.
Single Quotes and Double Quotes
Single quotes will just put exactly what is inside it single quotes can never sense any variable in its scope but Double quotes will evaluate first what is given in it. e.g.
$variable = 'some string'; echo '$variable'; // Output will be $variable echo "$variable"; // Output will be Some string
But if we use it for a simple string then output will be same in both cases and also the biggest difference between both it their processing speed. Single quotes are much faster that double quotes. its quite difficult to see in small programs. if you got a 1500 times a loop then you can easily see the difference.
echo and print
Echo and print both are use to output the information on user's screen but the difference is that print can return true or false means its useful if we want to use it in loop but echo is different it doesn't returns any value that's why it is faster than print otherwise the use of echo and print is save.
Use Nested Quotes
if you want to use Quotes inside the quotes means double quotes inside double quotes then you have to 'escape' them eg
echo "this is "an example"";
this is not gonna work because when it will show an error to use nested quotes you have to escape them with backslash (\). you can do that in following manner.
echo "this is \" an example \"";
the above given code will work fine. So these were some basic thing about PHP for beginners hope this will help.
Comments
Post a Comment
your Comment is sent for moderation, Thankyou