0
0
PHPprogramming~10 mins

Variable naming rules in PHP - Interactive Code Practice

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

Complete the code to declare a variable named $name with the value "John".

PHP
<?php
$[1] = "John";
?>
Drag options to blanks, or click blank then click option'
Aname!
B1name
Cmy-name
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Starting variable names with a number.
Using special characters like hyphens or exclamation marks in variable names.
2fill in blank
medium

Complete the code to declare a variable named $user_age and assign it the value 30.

PHP
<?php
$[1] = 30;
?>
Drag options to blanks, or click blank then click option'
Auser_age
Buser-age
Cuser age
Duser.age
Attempts:
3 left
💡 Hint
Common Mistakes
Using hyphens or dots in variable names.
Including spaces in variable names.
3fill in blank
hard

Fix the error in the variable declaration to make it valid.

PHP
<?php
$[1] = "Hello";
?>
Drag options to blanks, or click blank then click option'
A_greeting
B2greeting
Cgreeting!
Dgreeting message
Attempts:
3 left
💡 Hint
Common Mistakes
Starting variable names with numbers.
Using spaces or special characters in variable names.
4fill in blank
hard

Fill both blanks to declare a variable named $totalCount and assign it the value 100.

PHP
<?php
$[1] = [2];
?>
Drag options to blanks, or click blank then click option'
AtotalCount
B100
Cone_hundred
DcountTotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid variable names with spaces or special characters.
Assigning numbers as strings when an integer is expected.
5fill in blank
hard

Fill all three blanks to create an associative array with variable $person having keys name and age.

PHP
<?php
$[1] = [
    '[2]' => 'Alice',
    '[3]' => 25
];
?>
Drag options to blanks, or click blank then click option'
Aperson
Bname
Cage
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid variable names.
Using keys with spaces or special characters.