Filtering Arrays Using array_filter()
<?php
function array_display($array, $pre=FALSE) {
$tag = $pre ? 'pre' : 'p';
printf("<%s>%s</%s>\n", $tag, var_export($array, TRUE), $tag);
}
function is_romance($lang) {
return in_array($lang, array('French', 'Spanish', 'Portuguese', 'Italian'));
}
$countries = array( 'USA' => 'English', 'Spain' => 'Spanish', 'Brazil' => 'Portuguese');
$rom_countries = array_filter($countries, 'is_romance');
array_display($rom_countries, TRUE);
?>
Related examples in the same category