Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created December 13, 2012 13:52
Show Gist options
  • Save yitsushi/4276497 to your computer and use it in GitHub Desktop.
Save yitsushi/4276497 to your computer and use it in GitHub Desktop.
Array based "sprintf"
<?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