I wrote a function to filter the array, but a value is always missing. who can help me?

Source: Internet
Author: User
Is to filter the minimum value, the maximum value .. however, when user_array_filter ($ aTxt, & #039; After_A_Num & #039;, $ iMaxStamp);, it is found that a value equal to $ iMaxStamp is missing, who can help me see what's going on? I can't see any problem... {code ...}

Is to filter the minimum value, the maximum value ..
However, when
User_array_filter ($ aTxt, 'After _ A_Num ', $ iMaxStamp );
When I found that a value equal to $ iMaxStamp was missing, who would help me see what's going on?
I can't see any problems either ..

Function user_array_filter (& $ array, $ callback) // The Following 3rd parameters can be used as the $ callback parameter; {$ args = func_get_args (); // save all function parameters as an array. if (count ($ args) <2) exit ('function user_array_filter () parameter is incorrect. there are at least two parameters. '); if (count ($ args) = 2) // if the two parameters are $ arr and $ callback {foreach ($ array as $ k => $ v) {$ result = $ callback ($ v); if (! $ Result) // if the function returns false; {unset ($ array [$ k]) ;}} else {$ limit = $ args [2]; // [0]-> process arrays, [1]-> function, [2]-> value foreach ($ array as $ k => $ v) {$ result = $ callback ($ v, $ limit); if (! $ Result) // if the function returns false; {unset ($ array [$ k]) ;}}$ array = array_values ($ array ); // redefines the key;} function Before_A_Num ($ num, $ limit) {if ($ num <$ limit) return true; return false;} function After_A_Num ($ num, $ limit) {if ($ num> $ limit) return true; return false ;}

Reply content:

Is to filter the minimum value, the maximum value ..
However, when
User_array_filter ($ aTxt, 'After _ A_Num ', $ iMaxStamp );
When I found that a value equal to $ iMaxStamp was missing, who would help me see what's going on?
I can't see any problems either ..

Function user_array_filter (& $ array, $ callback) // The Following 3rd parameters can be used as the $ callback parameter; {$ args = func_get_args (); // save all function parameters as an array. if (count ($ args) <2) exit ('function user_array_filter () parameter is incorrect. there are at least two parameters. '); if (count ($ args) = 2) // if the two parameters are $ arr and $ callback {foreach ($ array as $ k => $ v) {$ result = $ callback ($ v); if (! $ Result) // if the function returns false; {unset ($ array [$ k]) ;}} else {$ limit = $ args [2]; // [0]-> process arrays, [1]-> function, [2]-> value foreach ($ array as $ k => $ v) {$ result = $ callback ($ v, $ limit); if (! $ Result) // if the function returns false; {unset ($ array [$ k]) ;}}$ array = array_values ($ array ); // redefines the key;} function Before_A_Num ($ num, $ limit) {if ($ num <$ limit) return true; return false;} function After_A_Num ($ num, $ limit) {if ($ num> $ limit) return true; return false ;}

Clarify that your current problem (the following pseudocode) is:

$ A = [1, 3, 45, 6, 6, 7, 7]; user_array_filter ($ a, 'After _ A_Num ', 6); var_dump ($ ); // Current result [7, 7, 45]

But what you expect is[6,6,7,7,45]Is that true?
If so, modifyAfter_A_NumThis function is greater than or equal.

I think it's not good to name your function like this.

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.