Comunitatea PHP Romania
 

 
array_unique

array_unique

(PHP 4 >= 4.0.1, PHP 5)

array_unique -- Removes duplicate values from an array

Description

array array_unique ( array array)

array_unique() takes input array and returns a new array without duplicate values.

Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.

Notã: Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same.

The first element will be used.

Avertisment

This was broken in PHP 4.0.4!

Exemplu 1. array_unique() example

$input = array ("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique ($input);
print_r($result);

This will output:

Array
(
    [b] => green
    [1] => blue
    [2] => red
)

Exemplu 2. array_unique() and types

$input = array (4,"4","3",4,3,"3");
$result = array_unique ($input);
var_dump($result);

The printout of the program above will be (PHP 4.0.6):

array(2) {
  [3]=>
  int(4)
  [4]=>
  int(3)
}

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
acasa , in pat
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Mortgages | Send Money Online | Loan | American Express credit card | Mortgages
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis