Optional: Values or Keys to be passed for checking.
Optional: 0: ARRAY_FILTER_USE_KEY , use only key for passing to callback function. 1 : ARRAY_FILTER_USE_BOTH : Use key and value both for passing to callback function.
We can use one callback function to check all the elements of the array. The callback function check each element and returns true or false. A new array is retuned with True value elements of the main array. Array key of parent array is preserved.
Filtering only integers.
We have one array with string and integer data. Let us try to filter elements and keep only integers.
In our new array $b all the integers take from old array $a is kept. Note that the associated keys of the elements are also retained. We used print_r to display our $b array.
We have used is_int a built in PHP function which returns true if the element is an integer. Now let us try to use one user defined function as callback function.