本文整理匯總了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));