0
0
PHPprogramming~10 mins

Echo vs print behavior in PHP - Interactive Practice

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

Complete the code to output the string using echo.

PHP
<?php
[1] "Hello, world!";
?>
Drag options to blanks, or click blank then click option'
Aecho
Bprint
Cprintf
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of echo here, which also works but is different.
2fill in blank
medium

Complete the code to output the string using print.

PHP
<?php
[1] "Hello, PHP!";
?>
Drag options to blanks, or click blank then click option'
Aecho
Bwrite
Cprint
Dprintf
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo instead of print here.
3fill in blank
hard

Complete the code to output the string using printf.

PHP
<?php
[1]("Hello!");
?>
Drag options to blanks, or click blank then click option'
Aecho
Bprintf
Cprint
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo or print instead of printf.
4fill in blank
hard

Fill 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'
Aprint
B$returnValue
Cecho
Dprintf
Attempts:
3 left
💡 Hint
Common Mistakes
Using echo which does not return a value.
5fill in blank
hard

Fill 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'
Aprint
B42
C$returnVal
Dprintf
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of printf for formatted output.