Ad space (banner)
๐Ÿ˜PHP Lessons
Lesson 17 / 68

Writing Comments

In this lesson you will learn how to write comments in PHP so your code still makes sense when you come back to it. This is for anyone searching for "PHP comment out syntax".

A comment is a note for humans that has no effect on execution. // or # starts a single-line comment and /* */ wraps a multi-line one. Recording why a piece of logic is needed pays off enormously later.

The sample code tries both single-line forms, // and #, as well as a multi-line /* */ comment. Having two ways to write a line comment is unusual, and teams often set a rule about which one to use.

A common stumbling block for beginners is writing so many comments that the code becomes harder to read. What the code does is usually clear from the code itself, so comments are most effective when they capture why a piece of logic is needed.

Comments are also the usual way to disable code temporarily (commenting out), which makes them indispensable in practice. Turning off a single line to check behaviour while debugging is a very common move.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run PHP directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)