Created
December 13, 2012 13:52
-
-
Save yitsushi/4276497 to your computer and use it in GitHub Desktop.
Array based "sprintf"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$html = array( | |
'form_start' => "<form id=%s action=%s name=%s method=%s class=%s>", | |
'other' => "suck %s", | |
'form_end' => "</form>" | |
); | |
$parameters = array( | |
'form_start' => array( 'p1', 'p2', 'p3', 'p4', 'p5' ), | |
'other' => array('array'), | |
'form_end' => array() | |
); | |
$contentArray = array_map(function($item, $key, $params) { | |
return vsprintf($item, $params); | |
}, $html, array_keys($html), $parameters); | |
echo implode('', $contentArray); | |
/** | |
* Output: | |
* <form id=p1 action=p2 name=p3 method=p4 class=p5>suck array</form> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment