简体   繁体   中英

array_walk an anonymous function

Is there a way I can get this array walk with my anonymous function to set the values?

$url = array('dog', 'cat', 'fish');

array_walk($url, function(&$value, &$key) {
    $url[$key] = str_replace('dog', '', $value);
});

echo '<pre>';
print_r($url);
echo '</pre>';

You are already passing the value by reference , so just do the following:

array_walk($url, function(&$value, &$key) {
    $value = str_replace('dog', '', $value);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM