Complete the code to print the number 10 using printf.
<?php $num = 10; printf("%[1]d", $num); ?>
The %d format specifier is used to print an integer number.
Complete the code to format a float number with 2 decimal places using sprintf.
<?php $price = 12.3456; $formatted = sprintf("%.[1]f", $price); echo $formatted; ?>
The %.2f format specifier formats the float with 2 decimal places.
Fix the error in the code to print a padded number with leading zeros using printf.
<?php $num = 7; printf("%[1]d", $num); ?>
The %07d format prints the number padded with zeros to width 7.
Fill both blanks to format a string with a minimum width and left alignment using printf.
<?php $name = "Bob"; printf("%[1][2]s", $name); ?>
The %-10s format prints the string left aligned in a field 10 characters wide.
Fill both blanks to format an integer in hexadecimal with uppercase letters and width 6 padded with zeros using sprintf.
<?php $num = 255; $hex = sprintf("%[1][2]X", $num); echo $hex; ?>
The %06X format prints the number in uppercase hexadecimal, padded with zeros to width 6.