array_walk() function applies a function to several or all elements in an array.
Its syntax is: int array_walk(array array, string func_name, [mixed data])
<?
//Using array_walk() to delete duplicates in an array:
function delete_dupes($element) {
static $last="";
if ($element == $last)
unset($element);
else
$last=$element;
}
$emails = array("b@b.com", "c@w.com", "b@b.com");
sort($emails);
print_r($emails);
echo '<br>';
reset($emails);
print_r($emails);
echo '<br>';
array_walk($emails,"delete_dupes");
print_r($emails);
echo '<br>';
?>
Related examples in the same category