What is the equivalent function in PHP for string formatting as in C#?

In PHP, you can use the sprintf function to achieve string formatting similar to C#. This function allows you to format a string with placeholders for variables that will be replaced with actual values.

// Example of using sprintf for string formatting in PHP
$first_name = "John";
$last_name = "Doe";
$age = 30;

$formatted_string = sprintf("Hello, my name is %s %s and I am %d years old.", $first_name, $last_name, $age);

echo $formatted_string; // Output: Hello, my name is John Doe and I am 30 years old.