Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP array_filter() Function
#1
The array_filter() function passes each value of a given array to a user defined function. If the user defined function allows, the current value from the array is returned into the result array.
Note: The function Iterates over each value in the array passing them to the callback function. If the callback function returns true, the current value from the array is returned into the result array. Array keys are preserved.


Parameter Description
array Required. Specifies the array to filter
callbackfunction Optional. Specifies the callback function to use
flag Optional. Specifies what arguments are sent to callback:
  • ARRAY_FILTER_USE_KEY - pass key as the only argument to callback (instead of the value)
  • ARRAY_FILTER_USE_BOTH - pass both value and key as arguments to callback (instead of the value)



Syntax
Code:
array_filter(array,callbackfunction);

Example
Code:
function name($var)
{
    return($var & 2);
}
$array=array("Samuel","Cooper",5,6,7);
print_r(array_filter($array,"name"));

Output
Code:
Array ( [3] => 6 [4] => 7 )

Another Example
Code:
function name($var)
{
    return($var & 'Samuel');
}
$array=array("Samuel","Cooper",5,6,7);
print_r(array_filter($array,"name"));

Output
Code:
Array ( [0] => Samuel [1] => Cooper )
To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING USE THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
  


Messages In This Thread
PHP array_filter() Function - by Kingsolomon - 09-29-2018, 06:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TIPS How to add one day in current date using php Kingsolomon 1 783 04-14-2020, 01:16 AM
Last Post: Shugudun
  How to session timeout warning with countdown using PHP, Ajax and HTML Kingsolomon 1 780 04-14-2020, 01:10 AM
Last Post: Shugudun
  TIPS How to get Page Loading Time using PHP Kingsolomon 2 937 04-14-2020, 01:01 AM
Last Post: Shugudun
  How to read more / hide text using Jquery and PHP Kingsolomon 1 808 04-14-2020, 12:57 AM
Last Post: Shugudun
  How to limit text length in php and provide 'Read more' link Kingsolomon 1 995 04-14-2020, 12:43 AM
Last Post: Shugudun

Forum Jump:


Users browsing this thread:
1 Guest(s)

PHP array_filter() Function00