0
0
PHPprogramming~10 mins

Assignment and compound assignment 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 assign the value 10 to the variable $x.

PHP
<?php
$x [1] 10;
echo $x;
Drag options to blanks, or click blank then click option'
A=
B=>
C+=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' for assignment.
Using '=>' which is for arrays, not assignment.
2fill in blank
medium

Complete the code to add 5 to the variable $count using a compound assignment operator.

PHP
<?php
$count = 10;
$count [1] 5;
echo $count;
Drag options to blanks, or click blank then click option'
A-=
B=
C*=
D+=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which replaces the value instead of adding.
Using '-=' or '*=' which subtract or multiply instead of add.
3fill in blank
hard

Fix the error in the code to multiply $num by 3 using a compound assignment operator.

PHP
<?php
$num = 4;
$num [1] 3;
echo $num;
Drag options to blanks, or click blank then click option'
A/=
B+=
C*=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' which adds instead of multiplies.
Using '/=' or '-=' which divide or subtract instead of multiply.
4fill in blank
hard

Complete the code to subtract 2 from $value and then assign the result back to $value.

PHP
<?php
$value = 15;
$value [1] 2;
echo $value;
Drag options to blanks, or click blank then click option'
A-=
B+=
C;
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' which adds instead of subtracts.
Forgetting the semicolon at the end of the statement.
5fill in blank
hard

Fill both blanks to divide $total by 4, assign the result back, and then add 1.

PHP
<?php
$total = 20;
$total [1] 4;
$total [2] 1;
echo $total;
Drag options to blanks, or click blank then click option'
A/=
B;
C+=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '/=' for division assignment.
Forgetting semicolons at the end of statements.
Using '+=' before dividing.