Q:

preg_replace with array index

I have an associative array, and a text with variables names inside, surrounded with brackets like this :
$message = "The value of var is: {var} ...-";

My array is like this:
$array=array('var'=>$var);

(Obviously this array can be bigger, and I don't know the name of the variables inside of it). Here is what I'm trying to do: I want to replace the {var} in my message by it's value in my array, like this:
$newMessage = preg_replace('#\{(.+)\}#',$array["$1"],$message);

Anyone knows how to do it?
Thank you very much!

A:

@Rizier123's comment helped me, here's the code I used to solve my problem:
$newMessage=preg_replace_callback('#\{(.+)\}#',function($match)use($array){
    return $array[$match[1]];
},$message);

