I have a function that takes the input of a user defined string and an array of data (key=>value), which looks like this;
$text = "Hi! My name is @name, and I live in @location.";
$dataArray = array("name" => "Mikal", "location" => "Oslo, Norway");
function MakeString($text, array $dataArray)
{
// return manipulated string...
}
I would like my function to s开发者_运维技巧wap the string @variables with data from the array, where string-variable matches array-key (if it does), so that the function returns:
"Hi! My name is Mikal, and I live in Oslo, Norway."
    foreach($dataArray as $key=>$value)
    {
     $text= str_replace("@".$key,$value,$text);
    }
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论