PHP: Array as the arguments part of the sprintf function
Using sprintf() function is a great way to integrate variables into string templates. It produces nice and readable code. But the drawback is that sprintf() does not support array as the argument part. As result the code may look less readable as number of parameters increases.
In that case vsprintf() is your friend. It works exact the same way as sprintf() except it accepts array instead of separate arguments.
$link = sprintf('<a href="%s">%s</a>', $url, $title); |
$params = array($url, $title); $link = vsprintf('<a href="%s">%s</a>', $params); |