Share a function, ask for a bug, ask for improvement ^

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.