替换php数组中的所有键

use*_*585 2 php arrays

这是我的数组:

['apple']['some code'] 
['beta']['other code']
['cat']['other code 2 ']
Run Code Online (Sandbox Code Playgroud)

我怎样才能用“!”替换所有“e”字母 在键名中并保留值,这样我就会得到类似的东西

['appl!']['some code'] 
['b!ta']['other code']
['cat']['other code 2 ']
Run Code Online (Sandbox Code Playgroud)

我发现了这个,但因为所有键的名称不同,所以我无法使用它

$tags = array_map(function($tag) {
    return array(
        'name' => $tag['name'],
        'value' => $tag['url']
    );
}, $tags);
Run Code Online (Sandbox Code Playgroud)

Ana*_*Die 5

我希望你的数组看起来像这样:

Array
(
    [apple] => some code
    [beta] => other code
    [cat] => other code 2 
)
Run Code Online (Sandbox Code Playgroud)

如果是,那么你可以像下面这样做:

$next_array = array();
foreach ($array as $key=>$val){
     $next_array[str_replace('e','!',$key)] = $val;
}
echo "<pre/>";print_r($next_array);
Run Code Online (Sandbox Code Playgroud)

输出:- https://3v4l.org/p9WFK