2010-01-12 76 views

回答

10

您可以只使用一个数组,并将所需的数据放入密钥中,因为密钥不能重复。

4

SplObjectStorage是最近的事情。

$storage = new SplObjectStorage; 
$obj1 = new StdClass; 

$storage->attach($obj1); 
$storage->attach($obj1); // not attached 
echo $storage->count(); // 1 

$obj2 = new StdClass; // different instance 
$obj3 = clone($obj2); // different instance 

$storage->attach($obj2); 
$storage->attach($obj3);  
echo $storage->count(); // 3 

顾名思义,它只能在对象工作虽然。如果您想要在标量类型中使用此功能,则必须使用新的Spl Types作为替代,以及使用Spl Data StructuresArrayObject替代阵列。

5

可以使用值的标准PHP数组,并将其传递通过array_unique功能:

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

输出:

array(2) { 
    [0] => int(4) 
    [2] => string(1) "3" 
}