[PHP] str_replace は検索文字列も置換文字列も複数指定できる

キチンと公式に書いてありました。

> * [PHP: str_replace – Manual](http://php.net/manual/ja/function.str-replace.php)

`mixed`

> mixed は、引数に多様な型 (全てである必要はない) を使うことができることを示します。
>
> [PHP: 本ドキュメントにおける疑似的な型および変数 – Manual](http://php.net/manual/ja/language.pseudo-types.php#language.types.mixed)

subject の中の search を全て replace に置換します。

– `$subject` が、対象文字列。
– `$search` が、検索する値。array も指定できる。
– `$replace` が、置換する値。array も指定できる。

下記のような array 指定の場合、対応する順に置換されていきます。

“`php
// You should eat pizza, beer, and ice cream every day となります
$subject = “You should eat fruits, vegetables, and fiber every day.”;
$search = array(“fruits”, “vegetables”, “fiber”);
$replace = array(“pizza”, “beer”, “ice cream”);

$newphrase = str_replace($search, $replace, $subject);
“`