Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Can you use an array as the arguments part of the sprintf function? if so - how?

Tags:

arrays

php

printf

From the PHP API reference:

string sprintf ( string $format [, mixed $args [, mixed $... ]] )

Returns a string produced according to the formatting string format.

Can $args be an array - If so how would I use it?

like image 334
Mazatec Avatar asked Sep 21 '10 16:09

Mazatec


1 Answers

vsprintf() is your friend. You cannot use an array in sprintf in any meaningfull way, but you can call vsprintf() with an array of arguments (which replaces sprintf 's seperate function arguments).

like image 152
Wrikken Avatar answered Oct 21 '22 10:10

Wrikken