PHP Comments
Comments let you add notes inside your code that PHP ignores when running the script. They help you and other developers understand what the code is doing, and can be used to temporarily disable a line of code while testing.
PHP supports single-line comments using // or #, and multi-line comments wrapped between /* and */, similar to many other C-style languages.
// single-line
# also single-line
/* multi
line */Single-line comments
Both // and # mark the rest of the line as a comment. // is the most commonly used style in PHP code.
Multi-line comments
Text between /* and */ can span several lines, making it useful for longer explanations or for commenting out blocks of code during debugging.
<?php
// This prints a greeting
echo "Hello!";
?>Hello!The comment is ignored by PHP and does not affect the output.
<?php
/* This block
explains the code below */
echo "Done";
?>DoneA multi-line comment can span several lines before the actual code runs.
Key points
- // and # both create single-line comments.
- /* ... */ creates a multi-line comment.
- Comments are ignored during script execution.
- Comments help explain code and can disable lines while testing.
