您可以使用标准的PHP数组值,并通过array_unique函数传递它:
$input = array(4, "4", "3", 4, 3, "3");
$result = array_unique($input);
var_dump($result);
Run Code Online (Sandbox Code Playgroud)
输出:
array(2) {
[0] => int(4)
[2] => string(1) "3"
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
顾名思义,这仅适用于对象。如果要将此方法与标量类型一起使用,则必须使用新的Spl Types进行替换,以及使用Spl Data Structures和ArrayObject进行数组替换。
| 归档时间: |
|
| 查看次数: |
1361 次 |
| 最近记录: |