,

PHP – make an array unique – remove duplicates

Code:

/**
 * Removes duplicate keys from an array
 *
 * @param array $array
 * @return array
 */
function array_unique_key($array) {
   $result = array();
   foreach (array_unique(array_keys($array)) as $tvalue) {
       $result[$tvalue] = $array[$tvalue];
   }
   return $result;
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *