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 . 
There is love in sharing
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  How to Stop Sending E-Mail Spam using PHP mail function Kingsolomon 1 59 11-12-2018, 04:38 PM
Last Post: Solomon
  Multiple file upload in php Kingsolomon 1 67 11-08-2018, 03:01 PM
Last Post: Solomon
  How to limit text length in php and provide 'Read more' link Kingsolomon 0 48 10-31-2018, 02:08 PM
Last Post: Kingsolomon
  How to read more / hide text using Jquery and PHP Kingsolomon 0 40 10-31-2018, 02:06 PM
Last Post: Kingsolomon
  Download simple HTML email templates Kingsolomon 0 43 10-31-2018, 02:05 PM
Last Post: Kingsolomon

Forum Jump:


Users browsing this thread:
1 Guest(s)

PHP array_filter() Function00