Today I had learned about PHP echo construct it is not a function , it is a language construct. By language construct I mean that meaning that it is an integral part of PHP itself. It allows us to output data on the users web browser. You can output values stored in a variable using echo or you can also output string data using echo. We can use both single quotation mark ‘ ‘ or double quotation mark ” “ while using echo. Double quotation mark are used when you want to output value of some variable to the browser in a program and your line must terminate with the semi colon ;
So previous example shows the use of echo with double quotation marks. As stated earlier we can also use it with single quotation marks as shown below
Now this would also output !I am echo construct! to the web browser.
In PHP we can also use echo to do arithmetic as can be seen in following example
Here line 2 is
echo 20+20;
This would output 40. This means echo command can be used for doing arithmetic and here note that quotation marks have not been used. You can also subtract , do division and multiplication using this echo construct.
Here line 3 is
echo ’20+20′;
This would literally output 20+20. This happens because quotation marks were used, this was processed as a string instead of a mathematical operation. And same thing would happen if we use double quotation marks instead of single quotation marks.
0 comments:
Post a Comment