How to write a comment in PHP

PHP comments are lines in the code that are ignored by the PHP interpreter. They are used to write notes or reminders for yourself or other developers. There are two types of PHP comments: single-line comments and multi-line comments.

Syntax Definition

    // Single-Line Comment

    /*
      Multi-Line Comment
    */

Single-Line Comment

Single-line comments are used to write a comment on a single line. They start with // and end at the end of the line.

    // This is a single-line comment.
    $name = "John"; // This variable stores the name "John".

Multi-Line Comment

Multi-line comments are used to write a comment that spans multiple lines. They start with /* and end with */.

    /*
      This is a multi-line comment.
      It spans multiple lines.
      Use it for longer notes or to comment out larger blocks of code.
    */

Parameter Values

Parameter Type Description
Comment String The comment text to be added in the code.

Technical Details

Details Value
Start Tag // or /*
End Tag End of line or */
Nesting Yes
Purpose Code Commenting

 

  Written by: Michael from Beginnrtuts.com     23-05-2023     Written in: PHP tutorials

2 Comments

  • Jeremy says:

    Thank you so much for posting this tutorial! It was really helpfull in teeching me how to write a comment in PHP. I formerely had no idea how to do it.

  • Micah says:

    Great tutotial! This is exactlly what I was lookinf for . I struggled with commentin in PHP before but now I undersatnd it better. The step-by-stehp instructions wre really helpfuel and easy to follow. Thahnk you for sharig this!

Leave a Reply

Your email address will not be published. Required fields are marked *