本文整理汇总了PHP中strcoll函数的典型用法代码示例。如果您正苦于以下问题:PHP strcoll函数的具体用法?PHP strcoll怎么用?PHP strcoll使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strcoll函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFetchTranslatedNamesSort
/**
* Test for the sort feature of country list
*/
public function testFetchTranslatedNamesSort()
{
$translatedCountriesList = array(
'FR' => 'France',
'GB' => 'Royaume-uni',
'DE' => 'Allemagne',
'NO' => 'Norvège' );
ezpINIHelper::setINISetting( array( 'fre-FR.ini', 'share/locale' ), 'CountryNames', 'Countries', $translatedCountriesList );
ezpINIHelper::setINISetting( 'site.ini', 'RegionalSettings', 'Locale', 'fre-FR' );
$countries = eZCountryType::fetchCountryList();
$this->assertInternalType( 'array', $countries, "eZCountryType::fetchCountryList() didn't return an array" );
$countryListIsSorted = true;
foreach( $countries as $country )
{
if ( !isset( $previousCountry ) )
{
$previousCountry = $country;
continue;
}
if ( strcoll( $previousCountry['Name'], $country['Name'] ) > 0 )
{
$countryListIsSorted = false;
break;
}
}
ezpINIHelper::restoreINISettings();
$this->assertTrue( $countryListIsSorted, "Country list isn't sorted" );
}
示例2: postprocessDefinition
public static function postprocessDefinition(&$machine_def)
{
// Make sure the names are always set
if (!empty($machine_def['properties'])) {
foreach ($machine_def['properties'] as $p_name => &$property) {
if (empty($property['name'])) {
$property['name'] = $p_name;
}
}
unset($property);
}
if (!empty($machine_def['actions'])) {
foreach ($machine_def['actions'] as $a_name => &$action) {
if (empty($action['name'])) {
$action['name'] = $a_name;
}
}
unset($action);
// Sort actions, so they appear everywhere in defined order
// (readers may provide them in random order)
uasort($machine_def['actions'], function ($a, $b) {
$aw = isset($a['weight']) ? $a['weight'] : 50;
$bw = isset($b['weight']) ? $b['weight'] : 50;
if ($aw == $bw) {
return strcoll(isset($a['label']) ? $a['label'] : $a['name'], isset($b['label']) ? $b['label'] : $b['name']);
} else {
return $aw - $bw;
}
});
}
}
示例3: cmp
private function cmp($aitem, $bitem)
{
if (!array_key_exists($this->_sortKey, $aitem)) {
return -$this->_sortVal;
} elseif (!array_key_exists($this->_sortKey, $bitem)) {
return -$this->_sortVal;
}
if (is_string($aitem[$this->_sortKey]) && is_string($bitem[$this->_sortKey])) {
return strcoll($aitem[$this->_sortKey], $bitem[$this->_sortKey]) * $this->_sortVal;
} else {
return $aitem[$this->_sortKey] > $bitem[$this->_sortKey] ? $this->_sortVal : -$this->_sortVal;
}
}
示例4: _sortByName
/**
* Helper method for uasort to sort applications by name.
*
* @param string $a
* @param string $a
*
* @return integer
*/
protected function _sortByName($a, $b)
{
return strcoll(_($a['name']), _($b['name']));
}
示例5: strCmp
/**
* Compare two strings
*/
function strCmp($a, $b)
{
global $ilCollator;
if (is_object($ilCollator)) {
return $ilCollator->compare(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0;
} else {
return strcoll(ilStr::strToUpper($a), ilStr::strToUpper($b)) > 0;
}
}
示例6: sort_folder_comparator
/**
* Callback for uasort() that implements correct
* locale-aware case-sensitive sorting
*/
protected function sort_folder_comparator($str1, $str2)
{
$path1 = explode($this->delimiter, $str1);
$path2 = explode($this->delimiter, $str2);
foreach ($path1 as $idx => $folder1) {
$folder2 = $path2[$idx];
if ($folder1 === $folder2) {
continue;
}
return strcoll($folder1, $folder2);
}
}
示例7: compare_definitions_by_name
/**
* Compare function for ordering by name in order_definitions().
*
* @param $first WPCF_Field_Definition_Abstract
* @param $second WPCF_Field_Definition_Abstract
*
* @return int
*/
public function compare_definitions_by_name($first, $second)
{
return strcoll(strtolower($first->get_name()), strtolower($second->get_name()));
}
示例8: strcmp_lok
function strcmp_lok($teksto1, $teksto2)
{
return strcoll($teksto1, $teksto2);
}
示例9: _sortByNotepad
/**
* Comparison function for sorting notes by notepad name.
*
* @param array $a Note one.
* @param array $b Note two.
*
* @return integer 1 if note one is greater, -1 if note two is greater;
* 0 if they are equal.
*/
protected static function _sortByNotepad($a, $b)
{
$aowner = $a['memolist_id'];
$bowner = $b['memolist_id'];
$ashare = $GLOBALS['mnemo_shares']->getShare($aowner);
$bshare = $GLOBALS['mnemo_shares']->getShare($bowner);
if ($aowner != $ashare->get('owner')) {
$aowner = $ashare->get('name');
}
if ($bowner != $bshare->get('owner')) {
$bowner = $bshare->get('name');
}
return strcoll($aowner, $bowner);
}
示例10: setlocale
<?php
setlocale(LC_COLLATE, 'NL');
echo strcoll("Hello World!", "Hello World!");
echo "<br>";
setlocale(LC_COLLATE, 'en_US');
echo strcoll("Hello World!", "Hello World!");
示例11: _sortCategoryArrayByName
protected function _sortCategoryArrayByName($a, $b)
{
return strcoll($a->getName(), $b->getName());
}
示例12: _sort
/**
* Helper method to sort an array of tickets.
*
* Used as callback to usort().
*
* @param array $a The first ticket to compare.
* @param array $b The second ticket to compare.
* @param string $sortby The field to sort by. If null, uses the field
* from self::sortBy().
* @param string $sortdir The direction to sort. If null, uses the value
* from self::sortDir().
*
* @return integer
*/
protected static function _sort($a, $b, $sortby = null, $sortdir = null)
{
if (is_null($sortby)) {
$sortby = self::$_sortBy;
}
if (is_null($sortdir)) {
$sortdir = self::$_sortDir;
}
if (is_array($sortby)) {
if (!isset($a[$sortby[0]])) {
$a[$sortby[0]] = null;
}
if (!isset($b[$sortby[0]])) {
$b[$sortby[0]] = null;
}
if (!count($sortby)) {
return 0;
}
if ($a['sort_by'][$sortby[0]] > $b['sort_by'][$sortby[0]]) {
return $sortdir[0] ? -1 : 1;
}
if ($a['sort_by'][$sortby[0]] === $b['sort_by'][$sortby[0]]) {
array_shift($sortby);
array_shift($sortdir);
return self::_sort($a, $b, $sortby, $sortdir);
}
return $sortdir[0] ? 1 : -1;
}
$a_val = isset($a['sort_by'][$sortby]) ? $a['sort_by'][$sortby] : null;
$b_val = isset($b['sort_by'][$sortby]) ? $b['sort_by'][$sortby] : null;
// Take care of the simplest case first
if ($a_val === $b_val) {
return 0;
}
if ((is_numeric($a_val) || is_null($a_val)) && (is_numeric($b_val) || is_null($b_val))) {
// Numeric comparison
return (int) ($sortdir ? $b_val > $a_val : $a_val > $b_val);
}
// Some special case sorting
if (is_array($a_val) || is_array($b_val)) {
$a_val = implode('', $a_val);
$b_val = implode('', $b_val);
}
// String comparison
return $sortdir ? strcoll($b_val, $a_val) : strcoll($a_val, $b_val);
}
示例13: coll
/**
* (PHP 4 >= 4.0.5, PHP 5)<br/>
* Locale based string comparison
* @link http://php.net/manual/en/function.strcoll.php
* @param string $string1 <p>
* The first string.
* </p>
* @param string $string2 <p>
* The second string.
* </p>
* @return int < 0 if <i>string1</i> is less than
* <i>string2</i>; > 0 if
* <i>string1</i> is greater than
* <i>string2</i>, and 0 if they are equal.
*/
static function coll($string1, $string2)
{
return strcoll($string1, $string2);
}
示例14: sort_func
/**
* sub-function to sort an array
*
* @param array $a
* @param array $b
*
* @return boolean true on success / false on error
* @static
*
*/
public static function sort_func($a, $b)
{
global $array_sortby, $array_sortorder;
// this comparison should give optimal results if
// locale is provided and mb string functions are supported
if ($array_sortorder == "asc") {
return ilStr::strCmp($a[$array_sortby], $b[$array_sortby]);
}
if ($array_sortorder == "desc") {
return !ilStr::strCmp($a[$array_sortby], $b[$array_sortby]);
return strcoll(ilStr::strToUpper($b[$array_sortby]), ilStr::strToUpper($a[$array_sortby]));
}
}
示例15: _sortEventStartTime
/**
* Used with usort() to sort events based on their start times.
*/
protected static function _sortEventStartTime($a, $b)
{
$diff = $a->start->compareDateTime($b->start);
if ($diff == 0) {
return strcoll($a->title, $b->title);
} else {
return $diff;
}
}