public static function sprintAssoc($string, $params)
    {
        foreach ($params as $key => $value) {
            $string = preg_replace("/%{($key)}/", $value, $string);
        }
        return $string;
    }
public static function sprintAssoc($string, $params)
    {
        foreach ($params as $key => $value) {
            $string = preg_replace("/%{($key)}/", $value, $string);
        }
        return $string;
    }
public static function sprintAssoc ( $ string , $ params ) { foreach ( $ params as $ key => $ value ) { $ string = preg_replace ( "/%{($key)}/" , $ value , $ string ) ; } return $ string ; }
Replace all occurrences of placeholder in string with values from associative array.

Example:
<code>
$sprintfString = "This is %{what}! %{what}? This is %{place}!";
$assocArray = array(
'what' => 'madness',
'place' => 'Sparta'
);
</code>
Result:
<code>
'This is madness! madness? This is Sparta!'
</code>

@param string $string
@param array $params
@return string
Replace all occurrences of placeholder in string with values from associative array .