0
0
PHPprogramming~5 mins

Comments in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of comments in PHP?
Comments are used to explain code, make it easier to understand, and to temporarily disable code without deleting it.
Click to reveal answer
beginner
How do you write a single-line comment in PHP?
You can write a single-line comment using either // or # at the start of the line.
Click to reveal answer
beginner
How do you write a multi-line comment in PHP?
Multi-line comments start with /* and end with */. Everything between is ignored by PHP.
Click to reveal answer
beginner
Can comments affect the execution of PHP code?
No, comments are ignored by the PHP engine and do not affect how the code runs.
Click to reveal answer
beginner
Example: What will this PHP code output?<br>
<?php
// echo 'Hello';
echo 'World';
?>
The output will be World because the first line is a comment and does not run.
Click to reveal answer
Which of the following is NOT a valid way to write a comment in PHP?
A<!-- This is a comment -->
B# This is a comment
C// This is a comment
D/* This is a comment */
What symbol starts a multi-line comment in PHP?
A//
B<!--
C#
D/*
What happens to the code inside comments when PHP runs?
AIt runs normally
BIt is ignored
CIt causes an error
DIt runs twice
Which comment style can be used for a single line in PHP?
A<!-- and -->
B/* and */
C// and #
DNone of the above
Why might a programmer use comments in their PHP code?
ATo explain the code to others
BTo speed up the code
CTo make the code run slower
DTo delete code permanently
Explain the different ways to write comments in PHP and when you might use each.
Think about quick notes versus longer explanations.
You got /4 concepts.
    Describe how comments affect PHP code execution and why they are important.
    Consider what happens when PHP runs code with comments.
    You got /4 concepts.