The vsprintf() function writes a formatted string to a variable.
Unlike sprintf(), the arguments in vsprintf(), are placed in an array. The array elements will be inserted at the percent (%) signs in the main string. This function works "step-by-step". At the first % sign, the first array element is inserted, at the second % sign, the second array element is inserted, etc.
If there are more % signs than arguments, you must use placeholders. A placeholder is inserted after the % sign, and consists of the argument- number and "\$". See example two.
string vsprintf ( string $format , array $args )
Operates as sprintf() but accepts an array of arguments, rather than a variable number of arguments.
Parameter | Description |
---|---|
format | See sprintf() for a description of format. |
argarray | Required. An array with arguments to be inserted at the % signs in the format string |
Return array values as a formatted string according to format (which is described in the documentation for sprintf()).