By comment it means that the developers do not want to execute that particular code.
It is generally to test that this particular code is running properly or not.
Single line comment: //
Multiline comment: /* .....
... */
Example:
1 2 3 4 5 6 7 | /*Multiple Line Comment */ // If one want to use to comment in their particular code segment then use like this $x = PHP /* Stands for */ stand for; echo $x; ?> |
Result:
PHP stand for
Explanation: If one want to comment a single line then they can use either – “//” or “#” or if one want to comment multiple line then they can use- “/* —code—-*/”
And in the last part you must have seen that particular section has been commented so that part would not be seen by anyone and result would be that part that is not commented.
Write a PHP program to add two numbers. Use appropriate comment when required.
addition program in php is very simple.
- Take two variables and give them initial value
- Add both variables and store in another variable
- print the sum
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <!DOCTYPE html> <html> <head> <title>Add Two Numbers in PHP</title> </head> <body> <?php /* PHP program to * add two numbers */ //declared and initialized variable a $a = 5; //declared and initialized variable b $b = 6; //added variable a and b and stored in sum $sum = $a + $b; //printing the sum value in browser echo "sum is $sum"; ?> </body> </html> |
Above program shows addition in PHP
Output
1 | sum is 11 |