PHP String vsprintf() FunctionThe vsprintf() function is an in-built function of PHP, which is used to display the array values as a formatted string. It works similar to the sprintf() function, but it accepts an array of arguments rather a variable number of arguments. PHP 4.1.0 and above versions support this function. In this function, the elements of the array along with the percent (%) signs in the main string. It displays the array values as the formatted string according to its format. It returns the formatted string. There are some other functions, which are similar to the vsprintf(). Related functionsvfprintf(), SyntaxThe syntax of the vsprintf() function is given below, which accepts two parameters, and both are mandatory. Parameters$format (required) - It is a mandatory parameter of vsprintf() function, which specifies how to format a variable in it. Possible format specifiers values:
Warning: The c specifier ignores the width and padding.Additional format values:
$array_args (required)- This is also a mandatory parameter of this function. It specifies an array containing the arguments to be inserted at the % signs in the format string. Return valuesThe vsprintf() function returns the formatted string. ExamplesBelow is the list of examples, by which we can learn the implementation of the vsprintf() function. Example 1 Output: 3542.000000 9324.000000 Example 2 Output: My enrollment number is: 3215 Next TopicPHP String Functions |