VOOZH about

URL: https://www.geeksforgeeks.org/php/how-to-write-comments-in-php/

⇱ How to write comments in PHP ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to write comments in PHP ?

Last Updated : 5 Sep, 2024

Comments are non-executable lines of text in the code that are ignored by the PHP interpreter. Comments are an essential part of any programming language. It help developers to understand the code, provide explanations, and make the codebase more maintainable.

Types of Comments in PHP

PHP supports two main types of comments: single-line and multi-line comments. Each type has its specific syntax and use cases.

Single-Line Comments in PHP

Single-line comments are used for brief explanations or notes that fit on a single line. The single line commments begin with either // or #.

Syntax

// Single-line comment using double slashes 
or
# Single-line comment using hash symbol

Example


Output
Hello GeeksforGeeks

Multi-Line Comments

Multi-line comments, also known as block comments, are used for longer explanations or when you need to comment out multiple lines of code. They begin with /* and end with */.

Syntax

/* 
This is a multi-line comment.
It contains multiple lines.
*/

Example


Output
Hello GeeksforGeeks
Comment