Skip to content

Instantly share code, notes, and snippets.

@vayn
Created May 22, 2010 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vayn/410118 to your computer and use it in GitHub Desktop.
Save vayn/410118 to your computer and use it in GitHub Desktop.
array_filter
<?php
function odd($var) {
return($var & 1);
}
function even($var) {
return(!($var & 1));
}
$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5);
$array2 = array(6, 7, 8, 9, 10, 11, 12);
echo "Odd :\n";
print_r(array_filter($array1, "odd"));
echo "Even:\n";
print_r(array_filter($array2, "even"));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment