<pre><code>&lt;?php
function toconv(string)
{
    $gogo = array("a" =&gt; "b","cd" =&gt; "e");
    $string = str_replace(
        array_keys( $gogo ),
        array_values( $gogo ),
        $string
    );
    return $string;
}
?&gt;
</code></pre>

<p>How can I implement that in JavaScript?</p>

String.replace() in Javascript receives regexes instead of strings and here's a translation. You need to append the g modifier to the regex to replace all occurrences instead of only the first one.
```
```
<script>
function toconv(str) {
    replacements = ['b','e'];
    regexes = [/a/g,/cd/g];

    for (i=0; i < regexes.length; i++) {
       str = str.replace(regexes[i],replacements[i]);
    }
    return str;
}

alert(toconv('acdacd'));
alert(toconv('foobar'));
</script>
```
```