Skip to Content
Introduction to PHP
PHP Comments

Sometimes, we want to include text in our files that we don’t want the computer to execute or display to the end user. We can do this with comments. Comments can be used to annotate our code to make it clearer to ourselves or others. They are also useful to prevent lines of code from being executed without deleting them.

In PHP, there are two main ways to add comments to our code. The first is single line comments. These are typically used for short explanations or points of clarification. Either # or // can be used to create a single line comment. Anything on the same line after these symbols is not executed by PHP.

For example:

// I will always remember this echo "Hello world"; // My first PHP statement


# I will always remember this echo "Hello, World!"; # My first PHP statement

The second type of comment is a multi-line comment. This is used for longer descriptions, a more detailed guide on how to properly use the section of code, or to prevent several lines of code from being executed. These comments are started with /* and ended with */.

For example:

/* "I've never thought of PHP as more than a simple tool to solve problems." - Rasmus Lerdorf */ echo "Hello, World!";



This PHP code includes both single and multi line comments. Take a moment to predict what will show up in the terminal and what will not. When you’re ready run the code to see if you were right.

Folder Icon

Take this course for free

Already have an account?