PHP Comments


Code comments represent lines that the PHP interpreter skips during execution. They are used to:

  • Explain code to yourself or others
  • Disable code temporarily for debugging
  • Add notes or reminders
php-comments

Single-Line Comment

Use // or # to write a one-line comment.

 

<?php
// This is a single-line comment
# This is also a single-line comment
echo "Hello, world!";
?> 

Multi-Line Comment

Use /* ... */ to write multiple lines of comment.

 

<?php
/*
  This is a multi-line comment.
  You can write multiple lines here.
*/
echo "PHP Comments Example";
?> 

Example

<?php
// Declare a variable
$name = "Alice";

/* 
  Display the name.
  You can also format it differently.
*/
echo "Hello, $name!";  // Greet the user
?> 

notepad
  • Use comments to explain complex logic
  • Avoid over-commenting obvious code
  • Keep comments up-to-date with code changes



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.