PHP printf() Function

printf() is a function in PHP used for formatting output. It works similar to the C language's printf() function. It allows you to format variables as strings with specified formats.

 
$name = "John";
$age = 30;
$height = 6.2;
// Using printf to format output
printf("Name: %s, Age: %d, Height: %.2f feet", $name, $age, $height);
 

  • %s is a placeholder for a string.
  • %d is a placeholder for an integer.
  • %.2f is a placeholder for a floating-point number with 2 decimal places.