note 77743 modified in function.array-unique by levim

From: Date: Sun, 20 Dec 2015 05:42:03 +0000
Subject: note 77743 modified in function.array-unique by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-204500@lists.php.net to get a copy of this message
This is a fast solution to remove duplicate values from an array when it contains only strings or only integers: <?php $array = array( 0 => 'Yellow', 1 => 'Green', 2 => 'Yellow', 3 => 'Blue', 4 => 'Yellow', ); $uniq = array_keys(array_flip($array)); var_export($uniq); /* Output: array ( 0 => 'Yellow', 1 => 'Green', 2 => 'Blue', ) */ ?> --was-- This is a solution to remove duplicate values from an array when it contains only strings or only integers: <?php $array = array( 0 => 'Yellow', 1 => 'Green', 2 => 'Yellow', 3 => 'Blue', 4 => 'Yellow', ); $uniq = array_keys(array_flip($array)); var_export($uniq); /* Output: array ( 0 => 'Yellow', 1 => 'Green', 2 => 'Blue', ) */ ?> http://php.net/manual/en/function.array-unique.php

« previous php.notes (#204500) next »