php判斷對象唯一
```php
class StreetLight {
public $id;
public $location;
public function __construct($id, $location) {
$this->id = $id;
$this->location = $location;
}
public function isUnique($streetLights) {
foreach ($streetLights as $light) {
if ($light->id == $this->id || $light->location == $this->location) {
return false;
}
}
return true;
}
}
$streetLights = array(
new StreetLight(, 'Location A'),
new StreetLight(, 'Location B')
);
$unique = new StreetLight(, 'Location C');
Is Unique: Yes
$notUnique = new StreetLight(, 'Location D');
Is Unique: No
```
在地理信息系統(tǒng)中使用經(jīng)緯度來判斷位置的唯性。在手交易和手圖書方面使用商品的序列號或者其他唯的標(biāo)識符來判斷物品的唯性。