Tuesday, 23 January 2018

Remove duplicated values

Removes duplicated entries in a array (only first level)
Warning this will remove all keys

function remove_duplicated_values($arr){
    $_a = array();
    while(list($key,$val) = each($arr)){
        $_a[$val] = 1;
    }
    return array_keys($_a);
}

remove_duplicated_values(array('a', 'b', 'c', 'a')); --> returns array('a','b','c')

0 comments:

Post a Comment