array_filter Online
Test PHP's array_filter() function online using real PHP 8.2. Filter elements from an array using a callback function or standard behavior. Perfect for cleaning data and removing unwanted elements.
array_filter(array $array, ?callable $callback = null, int $mode = 0): array PHP Array Input
Enter the array you want to filter
Filter Logic
Choose how to filter the array
Removes all "falsy" values (null, false, 0, "", [])
PHP Code
This is the actual PHP code that will be executed
Common Examples
array_filter() Function Guide
How It Works
The array_filter() function iterates over each value in the array passing them to the callback function. If the callback function returns true, the current value from array is returned into the result array. Array keys are preserved.
This function is essential for data manipulation in PHP. It allows you to selectively keep elements based on any condition you can define in code, making it incredibly powerful for processing lists, cleaning user input, or extracting specific data subsets.
Default Behavior
If no callback is supplied, all entries of the array equal to false (see converting to boolean) will be removed. This is often used to remove empty elements from an array.
Values considered empty/false in PHP include: "" (empty string), 0 (integer 0), null, false, and [] (empty array).
Request a Feature
Have an idea to improve this tool? Share your suggestions and help us make it better! (One request per day)

