Comments
Published Jul 31, 2021Updated Sep 9, 2021
Contribute to Docs
Comments are text placed inside code that is not executed. They are intended as documentation or explanation of the code they are a part of.
Syntax
PHP marks comments in three different ways:
//
will mark a comment from where it appears until the end of the line (or code block).#
will also mark a comment from where it appears until the end of the line (or code block).- Multi-line comments are marked by
/*
…*/
with everything in between marked as a comment.
Single line comments extend to the end of the line, or the end of the PHP block.
?>
will not be commented out, instead, ?>
will terminate the comment.
<?phpecho 'Testing 1, 2, 3...' // This is a single line comment/* Thisisa multi-line comment */echo 'Hello World!' # This is another single-line comment// This comment ends with the enclosing block ?>
Note that attempting to nest multi-line comments will result in an error. The first comment ends when the first */
is encountered,
leaving the remaining comment(s) to be executed.
<?php/* This is one multi-line comment/* But this inner comment will cause problems */This part of the comment will be executedsince the end of the inner comment ended the outercomment as well. */?>
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PHP on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours