PHP

PHP Menu

PHP

array_unique() Function - Definition, Syntax, Parameters, Examples

Definition

The array_unique() function removes duplicate values from an array. If two or more array values are the same, the first appearance will be kept and the other will be removed. The returned array will keep the first array item's key type.

Syntax

array_unique(array, sorttype)

Parameters

Parameter Description
array Required. Specifying an array.
sorttype Optional. Specifies how to compare the array elements/items. Possible values: SORT_STRING - Default. Compare items as strings; SORT_REGULAR - Compare items normally (don't change types); SORT_NUMERIC - Compare items numerically; SORT_LOCALE_STRING - Compare items as strings, based on current locale.

Example

<?php
$ages = array("Mark" => 22, "Jeff"=>22, "Mike" => 28); print_r(array_unique($ages));

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods