Example:
$sprintfString = "This is %{what}! %{what}? This is %{place}!";
$assocArray = array(
'what' => 'madness',
'place' => 'Sparta'
);
Result:
'This is madness! madness? This is Sparta!'
/** * @test */ public function shouldSprintfStringWithAssocArrayAsParam() { //given $sprintfString = "This is %{what}! %{what}? This is %{place}!"; $assocArray = array('what' => 'madness', 'place' => 'Sparta'); //when $resultString = Strings::sprintAssoc($sprintfString, $assocArray); //then $this->assertEquals('This is madness! madness? This is Sparta!', $resultString); }
public function translate($key, $params = array()) { $explodedKey = explode('.', $key); $translation = Arrays::getNestedValue($this->_labels, $explodedKey) ?: $key; return $this->localize(Strings::sprintAssoc($translation, $params)); }
public function getGeneratedFunctions() { return trim(Strings::sprintAssoc($this->_generatedFunctions, array('INDENT' => self::INDENT))); }