Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to output the string using echo.
PHP
<?php [1] "Hello, world!"; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of echo here, which also works but is different.
✗ Incorrect
The echo statement outputs the string directly.
2fill in blank
mediumComplete the code to output the string using print.
PHP
<?php [1] "Hello, PHP!"; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo instead of print here.
✗ Incorrect
The print statement outputs the string and returns 1.
3fill in blank
hardComplete the code to output the string using printf.
PHP
<?php [1]("Hello!"); ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo or print instead of printf.
✗ Incorrect
printf is a function and requires parentheses.
4fill in blank
hardFill both blanks to output the string and check the return value.
PHP
<?php $returnValue = [1] "Test"; echo "Return value: " . [2]; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo which does not return a value.
✗ Incorrect
print outputs the string and returns 1, stored in $returnValue.
5fill in blank
hardFill all three blanks to output the string with printf and store its return value.
PHP
<?php $returnVal = [1]("Number: %d", [2]); echo "Printed chars: " . [3]; ?>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of printf for formatted output.
✗ Incorrect
printf outputs formatted string, returns number of characters printed, stored in $returnVal.