Filtering Arrays in PHP


Filter elements of an array using a callback function, useful for removing unwanted values.

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