← Back to Gists

array filter callback

📝 PHP
jamesgarcia426
jamesgarcia426 · Level 12 ·

This snippet filters an array by passing each element through a custom callback function to include only those that return true.

PHP
$nums = [1,2,3,4,5];
$evens = arrayfilter($nums, function($n) { return $n % 2 == 0; });
printr($evens);

Comments

No comments yet. Start the discussion.