本文整理汇总了PHP中CMap::countValue方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::countValue方法的具体用法?PHP CMap::countValue怎么用?PHP CMap::countValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::countValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: countValue
/**
* Tells how many occurrences of a specified value there are in a map.
*
* 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 $value 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.
*
* @return int The number of such values in the map.
*
* @link CComparator.html CComparator
*/
public function countValue($value, $comparator = CComparator::EQUALITY)
{
return CMap::countValue($this->m_map, $value, $comparator);
}
示例2: testCountValue
public function testCountValue()
{
$map = ["one" => "a", "two" => "c", "three" => "b", "four" => "c", "five" => "d", "six" => "e", "seven" => "c", "eight" => "c", "nine" => "f", "ten" => "g", "eleven" => "h", "twelve" => "c"];
// Using the default comparator.
$this->assertTrue(CMap::countValue($map, "c") == 5);
// Using a custom comparator.
$comparator = function ($string0, $string1) {
return CString::toLowerCase($string0) === CString::toLowerCase($string1);
};
$this->assertTrue(CMap::countValue($map, "C", $comparator) == 5);
}