Using array_filter() to Filter Arrays in PHP


Filter elements of an array using a callback function for custom filtering logic.

Source Code

$numbers = [1, 2, 3, 4, 5, 6];
$even = array_filter($numbers, function($n) { return $n % 2 === 0; });
print_r($even);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments