0
0
PHPprogramming~10 mins

Why variables are needed in PHP - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable in PHP.

PHP
<?php
$[1] = 10;
echo $number;
?>
Drag options to blanks, or click blank then click option'
Anumber
B10
Cecho
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number as a variable name
Forgetting the dollar sign before the variable name
Using reserved words like 'var' as variable names
2fill in blank
medium

Complete the code to output the value of the variable.

PHP
<?php
$age = 25;
echo [1];
?>
Drag options to blanks, or click blank then click option'
Aecho
B$25
C$age
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign when echoing the variable
Trying to echo the variable name as a string without the dollar sign
3fill in blank
hard

Fix the error in the code by completing the variable assignment.

PHP
<?php
$[1] = 'Hello World';
echo $greeting;
?>
Drag options to blanks, or click blank then click option'
Aworld
Bmessage
CHello
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in assignment and output
Forgetting the dollar sign in variable names
4fill in blank
hard

Fill both blanks to create and output a variable holding a string.

PHP
<?php
$[1] = [2];
echo $name;
?>
Drag options to blanks, or click blank then click option'
Aname
B"John"
CJohn
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string values
Using a variable name that doesn't match the echo statement
5fill in blank
hard

Fill all three blanks to declare, assign, and output a variable with a number.

PHP
<?php
$[1] = [2];
echo $[3];
?>
Drag options to blanks, or click blank then click option'
Ascore
B100
Dpoints
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in assignment and echo
Putting quotes around numbers