0
0
PHPprogramming~5 mins

Printf and sprintf formatting in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does printf do in PHP?

printf formats a string and immediately prints it to the screen.

Click to reveal answer
beginner
How is sprintf different from printf?

sprintf formats a string but returns it instead of printing it. You can save or use the formatted string later.

Click to reveal answer
beginner
What does the format specifier %d mean in printf or sprintf?

%d is used to format an integer (whole number).

Click to reveal answer
intermediate
Explain the use of %0.2f in formatting.

%0.2f formats a floating-point number with 2 digits after the decimal point, adding zeros if needed.

Click to reveal answer
beginner
What happens if you use %s in printf?

%s formats a string. It inserts the string value into the formatted output.

Click to reveal answer
Which function prints the formatted string directly to the screen?
Aprintf
Bsprintf
Cprint_r
Decho
What does %f format specifier represent?
ABoolean
BInteger
CString
DFloating-point number
How do you format a number to always show 2 decimal places?
A%.2f
B%d
C%s
D%c
Which function returns the formatted string instead of printing it?
Aprintf
Bvar_dump
Csprintf
Dprint
What will printf("Hello %s", "World") output?
AHello %s
BHello World
CWorld Hello
DError
Describe the difference between printf and sprintf in PHP.
Think about when you want to show output immediately versus when you want to save it.
You got /3 concepts.
    Explain how to format a floating-point number to 3 decimal places using printf or sprintf.
    Look at the pattern for decimal precision in format specifiers.
    You got /3 concepts.