本文整理汇总了PHP中ArrayUtils::findLowerBound方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::findLowerBound方法的具体用法?PHP ArrayUtils::findLowerBound怎么用?PHP ArrayUtils::findLowerBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils::findLowerBound方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFindLowerBound
/**
* @covers ArrayUtils::findLowerBound
* @dataProvider provideFindLowerBound
*/
function testFindLowerBound($valueCallback, $valueCount, $comparisonCallback, $target, $expected)
{
$this->assertSame(ArrayUtils::findLowerBound($valueCallback, $valueCount, $comparisonCallback, $target), $expected);
}
示例2: getFirstLetter
public function getFirstLetter($string)
{
$string = strval($string);
if ($string === '') {
return '';
}
$firstChar = mb_substr($string, 0, 1, 'UTF-8');
// If the first character is a CJK character, just return that character.
if (ord($firstChar) > 0x7f && self::isCjk(UtfNormal\Utils::utf8ToCodepoint($firstChar))) {
return $firstChar;
}
$sortKey = $this->getPrimarySortKey($string);
// Do a binary search to find the correct letter to sort under
$min = ArrayUtils::findLowerBound([$this, 'getSortKeyByLetterIndex'], $this->getFirstLetterCount(), 'strcmp', $sortKey);
if ($min === false) {
// Before the first letter
return '';
}
$sortLetter = $this->getLetterByIndex($min);
if ($this->useNumericCollation) {
// If the sort letter is a number, return '0–9' (or localized equivalent).
// ASCII value of 0 is 48. ASCII value of 9 is 57.
// Note that this also applies to non-Arabic numerals since they are
// mapped to Arabic numeral sort letters. For example, ২ sorts as 2.
if (ord($sortLetter) >= 48 && ord($sortLetter) <= 57) {
$sortLetter = wfMessage('category-header-numerals')->numParams(0, 9)->text();
}
}
return $sortLetter;
}
示例3: getFirstLetter
function getFirstLetter($string)
{
$string = strval($string);
if ($string === '') {
return '';
}
// Check for CJK
$firstChar = mb_substr($string, 0, 1, 'UTF-8');
if (ord($firstChar) > 0x7f && self::isCjk(UtfNormal\Utils::utf8ToCodepoint($firstChar))) {
return $firstChar;
}
$sortKey = $this->getPrimarySortKey($string);
// Do a binary search to find the correct letter to sort under
$min = ArrayUtils::findLowerBound(array($this, 'getSortKeyByLetterIndex'), $this->getFirstLetterCount(), 'strcmp', $sortKey);
if ($min === false) {
// Before the first letter
return '';
}
return $this->getLetterByIndex($min);
}
示例4: findLowerBound
/**
* Do a binary search, and return the index of the largest item that sorts
* less than or equal to the target value.
*
* @deprecated in 1.23; use ArrayUtils::findLowerBound() instead
*
* @param array $valueCallback A function to call to get the value with
* a given array index.
* @param int $valueCount The number of items accessible via $valueCallback,
* indexed from 0 to $valueCount - 1
* @param array $comparisonCallback A callback to compare two values, returning
* -1, 0 or 1 in the style of strcmp().
* @param string $target The target value to find.
*
* @return int|bool The item index of the lower bound, or false if the target value
* sorts before all items.
*/
function findLowerBound($valueCallback, $valueCount, $comparisonCallback, $target)
{
wfDeprecated(__METHOD__, '1.23');
return ArrayUtils::findLowerBound($valueCallback, $valueCount, $comparisonCallback, $target);
}