sprintAssoc() public static method

Example: $sprintfString = "This is %{what}! %{what}? This is %{place}!"; $assocArray = array( 'what' => 'madness', 'place' => 'Sparta' ); Result: 'This is madness! madness? This is Sparta!'
public static sprintAssoc ( string $string, array $params ) : string
$string string
$params array
return string
示例#1
0
 /**
  * @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);
 }
示例#2
0
 public function translate($key, $params = array())
 {
     $explodedKey = explode('.', $key);
     $translation = Arrays::getNestedValue($this->_labels, $explodedKey) ?: $key;
     return $this->localize(Strings::sprintAssoc($translation, $params));
 }
示例#3
0
 public function getGeneratedFunctions()
 {
     return trim(Strings::sprintAssoc($this->_generatedFunctions, array('INDENT' => self::INDENT)));
 }