略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Ds\Set::contains

2024-12-22

Ds\Set::contains

(PECL ds >= 1.0.0)

Ds\Set::containsDetermines if the set contains all values

说明

public Ds\Set::contains(mixed ...$values): bool

Determines if the set contains all values.

注意:

Values of type object are supported. If an object implements Ds\Hashable, equality will be determined by the object's equals function. If an object does not implement Ds\Hashable, objects must be references to the same instance to be considered equal.

警告

All comparisons are strict (type and value).

参数

values

Values to check.

返回值

false if any of the provided values are not in the set, true otherwise.

范例

示例 #1 Ds\Set::contains() example

<?php
$set 
= new \Ds\Set([123]);

var_dump($set->contains(1));                // true
var_dump($set->contains(12));             // true
var_dump($set->contains(...[12]));        // true

var_dump($set->contains("1"));              // false
var_dump($set->contains(...[1234]));  // false

var_dump($set->contains(...[]));            // true
?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
bool(false)
bool(false)
bool(true)
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/ds-set.contains.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3