0

I'm stuck with this.

I've got a huge template that goes like this (simplified for this question):

$str = '[a] [b] [c]';

Then I have an array containing those above values:

$arr = array('[a]','[b]','[c]','[d]');

And finally, containing the values for replace comes an array that does not match the above one.

$rep = array("[d]" => "dVal","[a]" => "aVal","[b]" => "bVal", "[c]" => "cVal");

Can I some how, by some technique or any other php function match the $rep array to replace the key with the same name in $str. I current use str_replace.

sr_replace($arr,$rep,$str);//

The key names and names in $str are the same.

4

1 回答 1

2
str_replace(array_keys($rep), array_values($rep), $str)
于 2013-10-27T15:29:43.310 回答