Arr_Dupl_Del() : Array - Delete duplicates while retaining original element order

This function deletes similar elements in an array while maintaining the original order of the elements. This built-in PHP function array_unique() removes duplicates, but it also sorts the elements, which is sometimes undesirable.

Code
function Arr_Dupl_Del($Arr, $CaseSensitive = true) {
    /*
    Purpose
        Used to remove duplicate elements from an array without changing the order of the elements.
    Parameters
        Arr (array) = The array we're working with.
        CaseSensitive (optional boolean) = Determines if elements with differing case are considered duplicates.
            If True, similar elements with different cases are considered different.
            If False, similar elements with different cases are considered the same and are deleted.
            Default: True
    Return (array)
        Returns the specified array (Arr) with all duplicates removed.
        When duplicate elements exist, the first duplicate remains and all later-occurring ones are removed.
    Version History
        1.0 2012.11.15 Tested by Russ Tanner on PHP 5.3.8.
    */

    $r = array();
    
    if ($CaseSensitive) foreach($Arr as $x) { if (! in_array($x, $r)) $r[] = $x; }
    else { foreach($Arr as $x) { if (array_search(strtolower($x), array_map('strtolower', $r)) === false) { $r[] = $x; } } }
    
    return $r;

}


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)