且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PHP数组中搜索并替换值

更新时间:2023-11-07 09:34:34

虽然没有一个等效于示例代码的函数,但是您可以使用 array_keys (带有可选的搜索值参数), array_fill array_replace 来实现同一目的:

While there isn't one function equivalent to the sample code, you can use array_keys (with the optional search value parameter), array_fill and array_replace to achieve the same thing:

Tomas的编辑:该代码无法正常工作,已更正:

EDIT by Tomas: the code was not working, corrected it:

$ar = array_replace($ar,
    array_fill_keys(
        array_keys($ar, $value),
        $replacement
    )
);