本文整理汇总了PHP中Set::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::contains方法的具体用法?PHP Set::contains怎么用?PHP Set::contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::contains方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreate
public function testCreate()
{
$set = new Set(['a', 'b']);
$this->assertTrue($set->contains('a'));
$this->assertTrue($set->contains('b'));
$this->assertFalse($set->contains('c'));
$this->assertEquals(['a', 'b'], $set->toArray());
}
示例2: is_subset
public function is_subset(Set $other)
{
foreach ($this as $item) {
if (!$other->contains($item)) {
return false;
}
}
return true;
}
示例3: intersect
/**
* @param Set $other
* A set of items to intersect with this set
*
* @return Set
* A new set which contains only items in this
* Set and the given Set
*/
public function intersect(Set $other) : Set
{
$set = new Set();
foreach ($this as $element) {
if ($other->contains($element)) {
$set->attach($element);
}
}
return $set;
}
示例4: testContains
/**
* testContains method
*
* @return void
*/
public function testContains()
{
$a = array(0 => array('name' => 'main'), 1 => array('name' => 'about'));
$b = array(0 => array('name' => 'main'), 1 => array('name' => 'about'), 2 => array('name' => 'contact'), 'a' => 'b');
$this->assertTrue(Set::contains($a, $a));
$this->assertFalse(Set::contains($a, $b));
$this->assertTrue(Set::contains($b, $a));
}
示例5: contains
/**
* Determines if one Set or array contains the exact keys and values of another.
*
* @param array $val1 First value
* @param array $val2 Second value
* @return boolean true if $val1 contains $val2, false otherwise
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::contains
*/
public static function contains($val1, $val2 = null)
{
if (empty($val1) || empty($val2)) {
return false;
}
foreach ($val2 as $key => $val) {
if (is_numeric($key)) {
Set::contains($val, $val1);
} else {
if (!isset($val1[$key]) || $val1[$key] != $val) {
return false;
}
}
}
return true;
}
示例6: testContainsAnEmptySet
public function testContainsAnEmptySet()
{
$generator = new Set($this->singleElementGenerator);
$this->assertTrue($generator->contains([]));
}
示例7: contains
/**
* Checks if the collection contains the given element.
*
* @param mixed $value
* @param bool $strict Use a strict comparison (===) if TRUE
*/
public function contains($value, $strict = false)
{
if ($this->guard !== null) {
$this->guard->checkMemberGuard(new GuardPermission(__FUNCTION__, 'call'));
}
return $this->set->contains($value, $strict);
}
示例8: Set
echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
// readonly collection
echo "Construct as readonly\n";
$set2 = new Set($arr);
$set2->freeze();
Debug::dump($set2->isFrozen());
try {
echo "Adding Jack\n";
Debug::dump($set2->append($jack));
} catch (Exception $e) {
echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
try {
echo "Removing Jack\n";
$set2->remove($jack);
} catch (Exception $e) {
echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
try {
echo "Clearing\n";
$set2->clear();
} catch (Exception $e) {
echo get_class($e), ': ', $e->getMessage(), "\n\n";
}
foreach ($set2 as $key => &$val) {
$val = FALSE;
}
echo "Contains Jack?\n";
Debug::dump($set2->contains($jack));