str_replace() with two-dimensional array

Posted by Qiao on Stack Overflow See other posts from Stack Overflow or by Qiao
Published on 2010-03-08T04:28:23Z Indexed on 2010/03/08 4:36 UTC
Read the original article Hit count: 246

Filed under:

You can use arrays with str_replace():

$array_from = array ('from1', 'from2'); 
$array_to = array ('to1', 'to2');

$text = str_replace ($array_from, $array_to, $text);

But what if you have two-dimensional array?

$array_from_to = array (
 'from1' => 'to1';
 'from2' => 'to2';
);

How can you use it with str_replace()?
Speed matters - array is big enough.

© Stack Overflow or respective owner

Related posts about php