本文整理匯總了PHP中CMap::find方法的典型用法代碼示例。如果您正苦於以下問題:PHP CMap::find方法的具體用法?PHP CMap::find怎麽用?PHP CMap::find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CMap
的用法示例。
在下文中一共展示了CMap::find方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: isNameKnown
/**
* Determines if a time zone name is a known one.
*
* The method also searches among the backward compatible names.
*
* @param string $name The time zone name to be looked for (case-sensitive).
*
* @return bool `true` if the name is known, `false` otherwise.
*/
public static function isNameKnown($name)
{
assert('is_cstring($name)', vs(isset($this), get_defined_vars()));
$knownNamesWithBc = DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC);
return CMap::find($knownNamesWithBc, $name) && self::isNameIcuCompatible($name);
}
示例2: find
/**
* Determines if a map contains a specified value.
*
* You can use your own comparator for the search, but the default comparator has got you covered when searching
* for scalar values, such as `string`, `int`, `float`, and `bool`. And the default comparator is smart enough to
* know how to compare objects of those classes that conform to the IEquality or IEqualityAndOrder interface
* (static or not), including CUStringObject, CArrayObject, CMapObject, CTime etc. See the
* [CComparator](CComparator.html) class for more on this.
*
* @param mixed $whatValue The searched value.
* @param callable $comparator **OPTIONAL. Default is** `CComparator::EQUALITY`. The function or method to be
* used for the comparison of values while searching. If this parameter is provided, the comparator should take two
* parameters, with the first parameter being a value from the map and the second parameter being the searched
* value, and return `true` if the two values are equal and `false` otherwise.
* @param reference $foundUnderKey **OPTIONAL. OUTPUT.** If a value has been found after the method was called
* with this parameter provided, the parameter's value is being the first key under which the value was seen. If
* the key is a string, its output type is `CUStringObject`.
*
* @return bool `true` if such value was found in the map, `false` otherwise.
*
* @link CComparator.html CComparator
*/
public function find($whatValue, $comparator = CComparator::EQUALITY, &$foundUnderKey = null)
{
$found = CMap::find($this->m_map, $whatValue, $comparator, $foundUnderKey);
return $found;
}
示例3: testFind
public function testFind()
{
$map = ["one" => "a", "two" => "b", "three" => "c", "four" => "d", "five" => "e"];
// Using the default comparator.
$found = CMap::find($map, "c");
$this->assertTrue($found);
$foundUnderKey;
$found = CMap::find($map, "d", CComparator::EQUALITY, $foundUnderKey);
$this->assertTrue($found);
$this->assertTrue($foundUnderKey === "four");
$found = CMap::find($map, "C");
$this->assertFalse($found);
$found = CMap::find($map, "f");
$this->assertFalse($found);
// Using a custom comparator.
$comparator = function ($string0, $string1) {
return CString::toLowerCase($string0) === CString::toLowerCase($string1);
};
$foundUnderKey;
$found = CMap::find($map, "C", $comparator, $foundUnderKey);
$this->assertTrue($found);
$this->assertTrue($foundUnderKey === "three");
// Special case.
$map = CMap::make();
$found = CMap::find($map, "a");
$this->assertFalse($found);
}