$string = "Hello my name is {$data["name"]} and I'm {$data["age"]} years old.";
will do exactly what you want. If this doesn't suit you, try something like a regex loop, like
for ($data as $key=>$value){ $string = preg_replace("\{$key\}", $value, $string); }
Not tested, you can consult the documentation.
source share