note 112136 deleted from function.implode by googleguy
| From: | googleguy@php.net | Date: | Wed, 08 May 2013 21:59:22 +0000 |
| Subject: | note 112136 deleted from function.implode by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194744@lists.php.net to get a copy of this message | ||
Note Submitter: Boris Suska
----
In manner of printf and sprintf functions (where ending f stands for format) I'm adding
implodef.
function implodef($fmt, array $array) {
$result = '';
foreach ($array as $item) {
$result .= sprintf($fmt, $item);
}
return $result;
}
// usage, for example with PDO
$values = array('a' => 'first value', 'b' => 'second
value');
$set = implodef('
%1$s=:%1$s,', array_keys($values));
echo $set; // a=:a,b=:b