Home >Backend Development >PHP Tutorial > 【PHP】array_walk_recursive ― 对数组中的每个成员递归地施用用户函数

【PHP】array_walk_recursive ― 对数组中的每个成员递归地施用用户函数

WBOY
WBOYOriginal
2016-06-13 13:19:57837browse

【PHP】array_walk_recursive ― 对数组中的每个成员递归地应用用户函数
PHP里有这么一个函数:
bool array_walk_recursive ( array &$input , callback $funcname [, mixed $userdata ] )
对数组中的每个成员递归地应用用户函数,可以用来处理多维数组内数据,需要批处理数组内数据的时候使用这个函数非常方便。

function gb2312_to_utf8(&$value, $key) { 
    $value = iconv('gb2312', 'utf-8', $value);
}
array_walk_recursive($array, 'gb2312_to_utf8');

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn