假设有一个字符串“foo boo foo boo”,我想用 boo 替换所有 fooes,用 foo 替换 booes。预期输出是“boo foo boo foo”。我得到的是“foo foo foo foo”。如何获得预期输出而不是当前输出?
$a = "foo boo foo boo";
echo "$a\n";
$b = str_replace(array("foo", "boo"), array("boo", "foo"), $a);
echo "$b\n";
//expected: "boo foo boo foo"
//outputs "foo foo foo foo"