PHP Comments
What are Comments in PHP
A Comment in your PHP code is either a line or group of lines that aren’t executed by the PHP Parser. This means that your code inside a Commented line or Block isn’t going to be viewed or displayed to a website visitor.
Adding Comments to your PHP code is an important part of the process. Why? Because they are a helpful way to leave yourself notes on what you code does. Comments are also used for debugging purposes. You can comment out some code for testing purposes.
Three ways to add comments to your PHP Code
- // – the double forward slash is used for a single line comment
- # – is also used for a single line comment but not as often as the double forward slash
- /* */ – this can be used for a multiline comment block.
Let’s look at an example of each.
<!DOCTYPE html>
<html>
<body>
<?php
// This is a single line comment
# This is also a single line comment
/*
* This is a multiline comment block.
* Used to comment out large sections or blocks of code.
*/
?>
</body>
</html>
The Takeaway
Use comments in your code so you can remind yourself what you were looking to accomplish with your code. This is also helpful for your team members and others who might view your code.