note 77743 modified in function.array-unique by levim

From: Date: Sun, 20 Dec 2015 05:41:11 +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-204498@lists.php.net to get a copy of this message
This is a solution to remove duplicate values from an array when it contains only strings and 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 <?php $array[0] = "Yellow"; $array[1] = "Green"; $array[2] = "Yellow"; $array[3] = "Blue"; $array[4] = "Yellow"; $array = array_keys(array_flip($array)); //$array will output Yellow Green Blue ?> http://php.net/manual/en/function.array-unique.php

« previous php.notes (#204498) next »