Conteúdo do Curso
Introduction to PHP
Introduction to PHP
Comments 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:
index
<?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:
main
<?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:
main
<?php echo "info"; // Output "info" to the console ?>
A multi-line comment starts with /*
and ends with */
. It can span multiple lines:
main
<?php /* This is a multi-line comment. */ echo "Very useful topic"; ?>
Obrigado pelo seu feedback!