Share a function, ask for a bug, and seek improvement ^_^
We phper often use a lot of processing functions for numbers or strings.
Unfortunately, most of them do not support arrays
A flash of light, fix it.
The big guys who find it useful are holding a field
By the way, find some bugs and give some suggestions for improvement.
/**
* Allow functions to support multidimensional arrays by Wanderwind recursive calls
* Other function calls are recommended to implement
* @param string $FN Call Function name
* @param array $param parameters, usually passed in Func_get_args ()
* @param int $key parameter key values that require recursion
* @param boolean $check whether to detect function legality
* @return mixed return to $param[$key] Results
*/
function Fn2array ($FN, $param, $key = 0, $check = True) {
Default detection of function legitimacy when calling from external, multidimensional array recursion ignored
if ($check &&!function_exists ($FN)) {
return false;
}
Extracts the execution target, if the target non-array can be directly executed
$content = $param [$key];
if (!is_array ($content)) {
Return Call_user_func_array ($FN, $param);
}
Recursive execution if the target is an array
foreach ($content as & $val) {
$param [$key] = $val;
$val = Fn2array ($FN, $param, $key, false);
}
return $content;
}
function Wstripslashes () {
Return Fn2array (' Stripslashes ', Func_get_args ());
}
function Wsubstr () {
$param = Func_get_args ();
$param [3] = Isset ($param [3])? $param [3]: ' Utf-8 ';
Return Fn2array (' Mb_substr ', $param, 0);
}
$a = Array (
2 = ' \ ' aaaaaaaaaaaaaaa\ ',
Array (' \ ' ah ah ah ah ah oh ah ah oh ah oh, '),
Array (array (' \ ' sss\dasf\dasfasdsad\ ')),
);
Print_r (Wstripslashes ($a));
Print_r (Wsubstr ($a, 2, 5));
------to solve the idea----------------------
In support of the future.
------to solve the idea----------------------
And remembered the famous remark: The man who made the wheel again.
------to solve the idea----------------------
Not very clear about the meaning of the function, but come in and see
------to solve the idea----------------------
There's nothing wrong with making wheels, and choosing materials and crafts will do more good.