note 51763 modified in function.printf by aidan

From: Date: Tue, 28 Jun 2005 11:20:01 +0000
Subject: note 51763 modified in function.printf by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-91084@lists.php.net to get a copy of this message
[Editor's Note: Or just use vprintf...] If you want to do something like <?php printf('There is a difference between %s and %s', array('good', 'evil')); ?> (this doesn't work) instead of <?php printf('There is a difference between %s and %s', 'good', 'evil'); ?> you can use this function: <?php function printf_array($format, $arr) { return call_user_func_array('printf', array_merge((array)$format, $arr)); } ?> Use it the following way: <?php $goodevil = array('good', 'evil'); printf_array('There is a difference between %s and %s', $goodevil); ?> and it will print: There is a difference between good and evil --was-- If you want to do something like <?php printf('There is a difference between %s and %s', array('good', 'evil')); ?> (this doesn't work) instead of <?php printf('There is a difference between %s and %s', 'good', 'evil'); ?> you can use this function: <?php function printf_array($format, $arr) { return call_user_func_array('printf', array_merge((array)$format, $arr)); } ?> Use it the following way: <?php $goodevil = array('good', 'evil'); printf_array('There is a difference between %s and %s', $goodevil); ?> and it will print: There is a difference between good and evil http://php.net/manual/en/function.printf.php

« previous php.notes (#91084) next »