Project

General

Profile

Feature #27160 ยป array_unique.php

Stefan Froemken, 2011-06-01 10:11

 
<?php
$arr = array('Hello', 'You', 'Blue', 'Dog', 'Hello', 'You', 'Blue', 'Dog');
$arrUnique = array_unique($arr);
echo "array_unique<br />";
print_r($arrUnique);
echo "<br />";

$tempArray = array();
foreach($arr as $key => $val) {
$tempArray[$val] = $key;
}
$arrUnique = array_keys($tempArray);
echo "array_unique by foreach<br />";
print_r($arrUnique);
echo "<br />";

$arr = array(1 => 'Hello', 2 => 'You', 'color' => 'blue', 12 => 'dog', 6 => 'The sun is', 'color' => 'blue');
$arrUnique = array_unique($arr);
echo "array_unique<br />";
print_r($arrUnique);
echo "<br />";

$tempArray = array();
foreach($arr as $key => $val) {
$tempArray[$val] = $key;
}
$arrUnique = array_combine(array_values($tempArray), array_keys($tempArray));
echo "array_unique by foreach<br />";
print_r($arrUnique);
echo "<br />";
?>
    (1-1/1)