Multiline Comments
Multiline comments in PHP start with /*
and end with */
. Any text between these markers will be ignored by PHP.
Example: Multiline Comment as an Explanation
PHP
x
<?php
/*
The following statement will
print a welcome message
*/
echo "Welcome Home!";
?>
Using Multiline Comments to Ignore Code
Multiline comments can also be used to prevent blocks of code from being executed. This can be particularly useful when you need to temporarily disable parts of your code.
Example: Multiline Comment to Ignore Code
PHP
<?php
/*
echo "Welcome to my garage!";
echo "Feel free to browse the cars and motorcycles!";
*/
echo "Hello!";
?>
Comments Within Code
Multiline comments can also be used within a line of code to ignore certain parts of it.
Example: Ignoring Parts of Code
In this example, the + 15
part will be ignored in the calculation:
PHP
<?php
$x = 5 /* + 15 */ + 5;
echo $x; // Output will be 10
?>