Php Array Elements Filter Function

What is array_filter() Function?


The "array_filter()" function is used to filter elements of an array using a callback function.



In the above syntax "array" is the array, each value of the array elements is passed to the user defined "function", and the value returned "true" by the function is only displayed.

Example :

function funct1($s)
if ($s==="Cherry")
return true;
return false;
Result :

Array ( [1] => Cherry )

In the above example each value of the array "$a" is compared using the "function", the value "Cherry" is displayed as the condition returns "True".

PHP Topics

Ask Questions

Ask Question