Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Comments in PHP | First Acquaintance
Introduction to PHP
course content

Зміст курсу

Introduction to PHP

Introduction to PHP

1. First Acquaintance
2. Variables and Data Types
3. Conditional Statements
4. Arrays
5. Loops

bookComments in PHP

Usage of Comments


Developers often need tools to make their code easier to understand, both for themselves and for the people they work with. Comments are one such tool, as they allow us to explain parts of the code. The PHP interpreter ignores comments, so they don't affect the execution of the program. Comments can be used for:

1. Explaining what the code does:

php

index

copy
123
<?php echo "Correct"; // Output the word 'Correct' to the console ?>

The comment above clearly indicates to us what exactly this code does.

2. Commenting out code blocks to avoid errors at runtime:

php

main

copy
12345
<?php echo "Hello, World!"; // echo "Hello, World!"; // This line is commented out and won't execute echo "Hello, World!"; ?>

The comment above clearly demonstrates that the commented lines of code are ignored and do not affect the code execution result.

Single-Line and Multi-Line Comments


A single-line comment starts with // and continues to the end of the line:

php

main

copy
123
<?php echo "info"; // Output "info" to the console ?>

A multi-line comment starts with /* and ends with */. It can span multiple lines:

php

main

copy
1234567
<?php /* This is a multi-line comment. */ echo "Very useful topic"; ?>
How many times will the word `"Hello, World!"` be displayed in the console?

How many times will the word "Hello, World!" be displayed in the console?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
We're sorry to hear that something went wrong. What happened?
some-alt