本文整理汇总了PHP中CMap::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::filter方法的具体用法?PHP CMap::filter怎么用?PHP CMap::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::filter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: knownNamesForCountry
/**
* Returns the names of the time zones that are known for a specified country.
*
* If the country's code is not recognized for any reason, the entire list of the known time zone names is
* returned.
*
* @param string $countryCode The two-letter code of the country, as provided by ISO 3166.
*
* @return CArrayObject The known time zone names for the country specified, of type `CUStringObject`.
*/
public static function knownNamesForCountry($countryCode)
{
assert('is_cstring($countryCode)', vs(isset($this), get_defined_vars()));
$paNames = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $countryCode);
$paNames = CMap::filter($paNames, "CTimeZone::isNameIcuCompatible");
$names = CArray::fromPArray($paNames);
if (is_cmap($paNames) && !CArray::isEmpty($names)) {
return oop_a($names);
} else {
return oop_a(self::knownNames());
}
}
示例2: filter
/**
* Filters the key-value pairs in a map by calling a function or method on each value and returns a new map with
* only those key-value pairs that were let through by the filter.
*
* The map is not modified by this method.
*
* @param callable $filter The function or method to be used for filtering. The filter should take a value as a
* parameter and return `true` if the corresponding key-value pair should make its way into the resulting map and
* `false` if not.
*
* @return CMapObject The filtered map.
*/
public function filter($filter)
{
return self::fromPArray(CMap::filter($this->m_map, $filter));
}
示例3: testFilter
public function testFilter()
{
$map = ["one" => 1, "two" => 2, "three" => 3, "four" => 4, "five" => 5, "six" => 6, "seven" => 7, "eight" => 8, "nine" => 9, "ten" => 10];
$map = CMap::filter($map, function ($value) {
return CMathi::isEven($value);
});
$this->assertTrue(CMap::equals($map, ["two" => 2, "four" => 4, "six" => 6, "eight" => 8, "ten" => 10]));
}