Challenge - 5 Problems
PHP Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PHP print statement?
Look at the PHP code below. What will it print when run?
PHP
<?php print "Hello, " . "world!"; ?>
Attempts:
2 left
💡 Hint
Remember that the dot (.) joins strings exactly as they are.
✗ Incorrect
The dot operator concatenates strings without adding or removing spaces. So "Hello, " and "world!" join exactly as 'Hello, world!'.
❓ Predict Output
intermediate2:00remaining
What does this print statement output?
What will this PHP code print?
PHP
<?php print(5 + 3); ?>
Attempts:
2 left
💡 Hint
The plus sign adds numbers, not strings, when used with numbers.
✗ Incorrect
The expression 5 + 3 evaluates to 8, so print outputs 8.
❓ Predict Output
advanced2:00remaining
What is the output of this PHP print with variables?
What will this PHP code print?
PHP
<?php $name = "Alice"; print "Hello, $name!"; ?>
Attempts:
2 left
💡 Hint
Variables inside double quotes are replaced by their values.
✗ Incorrect
In double quotes, PHP replaces $name with its value 'Alice', so it prints 'Hello, Alice!'.
❓ Predict Output
advanced2:00remaining
What error does this PHP print statement cause?
What error will this PHP code produce?
PHP
<?php print 'Hello, $name!'; ?>
Attempts:
2 left
💡 Hint
Single quotes do not replace variables with their values.
✗ Incorrect
Single quotes print the string exactly as is, so it prints 'Hello, $name!'. No error occurs.
❓ Predict Output
expert2:00remaining
What is the output of this complex PHP print statement?
What will this PHP code print?
PHP
<?php print "Sum: " . (2 + 3) . ", Product: " . (2 * 3); ?>
Attempts:
2 left
💡 Hint
Remember operator precedence: concatenation (.) and multiplication (*) have different priorities.
✗ Incorrect
Operator precedence dictates that * has higher precedence than ., so 2 * 3 = 6 first. Then the concatenations happen left-to-right: "Sum: " . 5 . ", Product: " . 6 results in "Sum: 5, Product: 6".