PHP/Data Structure/array unique — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 07:02, 26 мая 2010
array_unique( ) filters an array so that a value can only appear once.
<?
$toppings2 = array("Peppers", "Ham", "Cheese", "Peppers");
$toppings2 = array_unique($toppings2);
?>
To get the unique values in an array: array_unique() function
<?
$countries= array("Germany" => "German", "France" => "French", "Spain" => "Spanish");
$languages = array_unique($countries);
printf("%s,", var_export($languages, TRUE));
?>
Working with Unique Values
<?php
$countries = array( "USA" => "English", "Spain" => "Spanish",
"Brasil" => "Portuguese", "UK" => "English",
"France" => "French", "Argentina" => "Spanish");
$languages = array_unique($countries);
printf("<pre>%s</pre>\n", var_export($languages, TRUE));
$languages = array_unique( array_values($countries) );
printf("<pre>%s</pre>\n", var_export($languages, TRUE));
$languages = array_values( array_unique($countries) );
printf("<pre>%s</pre>\n", var_export($languages, TRUE));
?>