本文整理汇总了PHP中uksort函数的典型用法代码示例。如果您正苦于以下问题:PHP uksort函数的具体用法?PHP uksort怎么用?PHP uksort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uksort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: toOptionArray
/**
* @param bool $isMultiselect
* @return array
*/
public function toOptionArray($isMultiselect = false)
{
if (!$this->_options) {
$countriesArray = $this->_countryCollectionFactory->create()->load()->toOptionArray(false);
$this->_countries = [];
foreach ($countriesArray as $a) {
$this->_countries[$a['value']] = $a['label'];
}
$countryRegions = [];
$regionsCollection = $this->_regionCollectionFactory->create()->load();
foreach ($regionsCollection as $region) {
$countryRegions[$region->getCountryId()][$region->getId()] = $region->getDefaultName();
}
uksort($countryRegions, [$this, 'sortRegionCountries']);
$this->_options = [];
foreach ($countryRegions as $countryId => $regions) {
$regionOptions = [];
foreach ($regions as $regionId => $regionName) {
$regionOptions[] = ['label' => $regionName, 'value' => $regionId];
}
$this->_options[] = ['label' => $this->_countries[$countryId], 'value' => $regionOptions];
}
}
$options = $this->_options;
if (!$isMultiselect) {
array_unshift($options, ['value' => '', 'label' => '']);
}
return $options;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:33,代码来源:Allregion.php
示例2: generate_oauth_signature
/**
* Generate OAuth signature, see server-side method here:
*
* @link https://github.com/WIC/woocommerce/blob/master/includes/api/class-wc-api-authentication.php#L196-L252
*
* @since 2.0
*
* @param array $params query parameters (including oauth_*)
* @param string $http_method, e.g. GET
* @return string signature
*/
public function generate_oauth_signature($params, $http_method)
{
$base_request_uri = rawurlencode($this->url);
if (isset($params['filter'])) {
$filters = $params['filter'];
unset($params['filter']);
foreach ($filters as $filter => $filter_value) {
$params['filter[' . $filter . ']'] = $filter_value;
}
}
// normalize parameter key/values and sort them
// Make a waring if param is an array
$params = @$this->normalize_parameters($params);
uksort($params, 'strcmp');
// form query string
$query_params = array();
foreach ($params as $param_key => $param_value) {
$query_params[] = $param_key . '%3D' . $param_value;
// join with equals sign
}
$query_string = implode('%26', $query_params);
// join with ampersand
// form string to sign (first key)
$string_to_sign = $http_method . '&' . $base_request_uri . '&' . $query_string;
$secret = $this->consumer_secret;
if (preg_match('/wc-api\\/v3/', $this->url)) {
// @see https://stackoverflow.com/questions/31976059/woocommerce-api-v3-authentication-issue
$secret .= '&';
}
return base64_encode(hash_hmac(self::HASH_ALGORITHM, $string_to_sign, $secret, true));
}
开发者ID:jfraczkiewicz,项目名称:WooCommerce-REST-API-Client-Library,代码行数:42,代码来源:ClientAuthentication.php
示例3: sortKeys
protected function sortKeys()
{
switch (strtoupper($this->getOption('key_sort'))) {
case 'NONE':
break;
case 'SORT_REGULAR':
ksort($this->value, SORT_REGULAR);
break;
case 'SORT_NUMERIC':
ksort($this->value, SORT_NUMERIC);
break;
case 'SORT_STRING':
ksort($this->value, SORT_STRING);
break;
case 'SORT_STRING_CASE':
uksort($this->value, "strcasecmp");
//ksort($this->value,SORT_STRING | SORT_FLAG_CASE); php 5.4
break;
case 'SORT_LOCAL_STRING':
ksort($this->value, SORT_LOCALE_STRING);
break;
case 'SORT_NATURAL':
uksort($this->value, "strnatcasecmp");
// ksort($this->value,SORT_NATURAL); php 5.4
break;
default:
case 'SORT_NATURAL_CASE':
uksort($this->value, "strnatcasecmp");
//ksort($this->value,SORT_NATURAL | SORT_FLAG_CASE); php 5.4
break;
}
}
开发者ID:apelon-ohie,项目名称:ihris-site,代码行数:32,代码来源:I2CE_FormField_ASSOC_LIST.php
示例4: prepare_items
function prepare_items()
{
global $ct;
$ct = current_theme_info();
$themes = get_allowed_themes();
if (!empty($_REQUEST['s'])) {
$search = strtolower(stripslashes($_REQUEST['s']));
$this->search = array_merge($this->search, array_filter(array_map('trim', explode(',', $search))));
$this->search = array_unique($this->search);
}
if (!empty($_REQUEST['features'])) {
$this->features = $_REQUEST['features'];
$this->features = array_map('trim', $this->features);
$this->features = array_map('sanitize_title_with_dashes', $this->features);
$this->features = array_unique($this->features);
}
if ($this->search || $this->features) {
foreach ($themes as $key => $theme) {
if (!$this->search_theme($theme)) {
unset($themes[$key]);
}
}
}
unset($themes[$ct->name]);
uksort($themes, "strnatcasecmp");
$per_page = 24;
$page = $this->get_pagenum();
$start = ($page - 1) * $per_page;
$this->items = array_slice($themes, $start, $per_page);
$this->set_pagination_args(array('total_items' => count($themes), 'per_page' => $per_page));
}
开发者ID:vivekkodira1,项目名称:wordpress,代码行数:31,代码来源:class-wp-themes-list-table.php
示例5: build_http_query
public static function build_http_query($params = array())
{
if (empty($params)) {
return "";
}
// Urlencode both keys and values
$keys = Utility::urlencode_rfc3986(array_keys($params));
$values = Utility::urlencode_rfc3986(array_values($params));
$params = array_combine($keys, $values);
// params are sorted by name, using lexicographical byte value ordering.
// Ref: Spec: 9.1.1 (1)
uksort($params, 'strcmp');
$pairs = array();
foreach ($params as $parameter => $value) {
if (is_array($value)) {
// If two or more params share the same name, they are sorted by their value
// Ref: Spec: 9.1.1 (1)
natsort($value);
foreach ($value as $duplicate_value) {
$pairs[] = $parameter . '=' . $duplicate_value;
}
} else {
$pairs[] = $parameter . '=' . $value;
}
}
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
// Each name-value pair is separated by an '&' character (ASCII code 38)
return implode('&', $pairs);
}
开发者ID:johnshopkins,项目名称:twitterhook,代码行数:29,代码来源:Utility.php
示例6: buildHttpQuery
/**
* @param $params
*
* @return string
*/
public static function buildHttpQuery($params)
{
if (!$params) {
return '';
}
// Urlencode both keys and values
$keys = Util::urlencodeRfc3986(array_keys($params));
$values = Util::urlencodeRfc3986(array_values($params));
$params = array_combine($keys, $values);
// Parameters are sorted by name, using lexicographical byte value ordering.
// Ref: Spec: 9.1.1 (1)
uksort($params, 'strcmp');
$pairs = array();
foreach ($params as $parameter => $value) {
if (is_array($value)) {
// If two or more parameters share the same name, they are sorted by their value
// Ref: Spec: 9.1.1 (1)
// June 12th, 2010 - changed to sort because of issue 164 by hidetaka
sort($value, SORT_STRING);
foreach ($value as $duplicateValue) {
$pairs[] = $parameter . '=' . $duplicateValue;
}
} else {
$pairs[] = $parameter . '=' . $value;
}
}
// For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
// Each name-value pair is separated by an '&' character (ASCII code 38)
return implode('&', $pairs);
}
开发者ID:TechLoCo,项目名称:twitteroauth,代码行数:35,代码来源:Util.php
示例7: __construct
/**
* @param array $map (location => weight)
*/
public function __construct(array $map)
{
$map = array_filter($map, function ($w) {
return $w > 0;
});
if (!count($map)) {
throw new UnexpectedValueException("Ring is empty or all weights are zero.");
}
$this->sourceMap = $map;
// Sort the locations based on the hash of their names
$hashes = array();
foreach ($map as $location => $weight) {
$hashes[$location] = sha1($location);
}
uksort($map, function ($a, $b) use($hashes) {
return strcmp($hashes[$a], $hashes[$b]);
});
// Fit the map to weight-proportionate one with a space of size RING_SIZE
$sum = array_sum($map);
$standardMap = array();
foreach ($map as $location => $weight) {
$standardMap[$location] = (int) floor($weight / $sum * self::RING_SIZE);
}
// Build a ring of RING_SIZE spots, with each location at a spot in location hash order
$index = 0;
foreach ($standardMap as $location => $weight) {
// Location covers half-closed interval [$index,$index + $weight)
$this->ring[$location] = array($index, $index + $weight);
$index += $weight;
}
// Make sure the last location covers what is left
end($this->ring);
$this->ring[key($this->ring)][1] = self::RING_SIZE;
}
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:37,代码来源:HashRing.php
示例8: refresh
function refresh()
{
// create basic files if missing
self::$_archive_file = $this->_create(FILE_ARCHIVE);
self::$_trash_file = $this->_create(FILE_TRASH);
$paths = glob(self::$_data_dir . "*" . EXT);
// what if only trash and archive exist? Create a default task file
if (count($paths) <= 2) {
self::_create(self::$_default_file);
$paths[] = self::$_data_dir . self::$_default_file . EXT;
}
$names = str_replace(array(EXT, self::$_data_dir), '', $paths);
self::$_names = $names;
$modified = array_map(function ($path) {
return filemtime($path);
}, $paths);
self::$_files = array();
$count = count($paths);
for ($i = 0; $i < $count; $i++) {
$name = $names[$i];
if ($name == self::$_archive_file) {
$type = TAB_ARCHIVE;
} elseif ($name == self::$_trash_file) {
$type = TAB_TRASH;
} else {
$type = TAB_NORMAL;
}
self::$_files[$name] = new File($i, $name, $paths[$i], $modified[$i], $type);
}
// Basic initial sort: case insensitive, with symbol first (i.e. '_')
uksort(self::$_files, 'strcasecmp');
}
开发者ID:ace-space,项目名称:taskpaperplus-server,代码行数:32,代码来源:files.class.php
示例9: get_lang
/**
* Translate strings to the current locale
*
* When using get_lang(), try to put entire sentences and strings in
* one get_lang() call. This makes it easier for translators.
*
* @code
* $msg = get_lang('Hello %name',array('%name' => $username))
* @endcode
*
* @param $name
* A string containing the English string to translate.
* @param $var_to_replace
* An associative array of replacements to make after translation. Incidences
* of any key in this array are replaced with the corresponding value.
* @return
* The translated string.
*/
function get_lang($name, $var_to_replace = null)
{
global $_lang;
$translation = '';
if (isset($_lang[$name])) {
$translation = $_lang[$name];
} else {
// missing translation
$translation = $name;
}
if (!empty($var_to_replace) && is_array($var_to_replace)) {
if (claro_debug_mode()) {
foreach (array_keys($var_to_replace) as $signature) {
if (false === strpos($translation, $signature)) {
if (is_numeric($signature) && isset($var_to_replace[$signature + 1])) {
pushClaroMessage($signature . ' not in varlang.<br>
"<b>' . $var_to_replace[$signature] . '</b>" is probably the key of "<b>' . $var_to_replace[$signature + 1] . '</b>"', 'translation');
} else {
pushClaroMessage($signature . ' not in varlang.', 'translation');
}
}
}
}
uksort($var_to_replace, 'cmp_string_by_length');
return strtr($translation, $var_to_replace);
} else {
// return translation
return $translation;
}
}
开发者ID:rhertzog,项目名称:lcs,代码行数:48,代码来源:language.lib.php
示例10: match
public function match(Route $route)
{
uksort($this->map, function ($path1, $path2) {
$path1Length = strlen($path1);
$path2Length = strlen($path2);
return $path1Length == $path2Length ? 0 : ($path1Length < $path2Length ? 1 : -1);
});
$missingPath = $route->getMissingPath();
foreach ($this->map as $path => $parameters) {
if (stripos($missingPath, $path) !== 0) {
continue;
}
if (!$this->allowPartialMatches && strtolower(trim($path, '/')) != strtolower(trim($missingPath, '/'))) {
continue;
}
$route->matchPath($path);
foreach ($parameters as $key => $value) {
$route->setParameter($key, $value);
}
if (trim($route->getMissingPath(), '/') == '') {
$route->found();
}
break;
}
}
开发者ID:binsoul,项目名称:net-http-router,代码行数:25,代码来源:StaticMatcher.php
示例11: Klutz
/**
* Constructor - Parse the /config/comics.php config file and store
* the results in $comic. Also tries to validate all the data it can
* and adjust case, etc., to more predictible consistency than humans
* editing config files can give. :)
*
* @param integer $sort Sorting method to use
*/
function Klutz($sort = KLUTZ_SORT_NAME)
{
$this->sort = $sort;
// Load the list of comics from the config file.
include_once KLUTZ_BASE . '/config/comics.php';
if (isset($comics)) {
$this->comics = $comics;
}
if ($this->sort != KLUTZ_SORT_NOSORT) {
uksort($this->comics, array($this, '_sortComics'));
}
foreach (array_keys($this->comics) as $index) {
if (empty($this->comics[$index]['days'])) {
$this->comics[$index]['days'] = array_unique($this->days);
} else {
if (!is_array($this->comics[$index]['days'])) {
if (Horde_String::lower($this->comics[$index]['days']) == 'random') {
$this->comics[$index]['days'] = 'random';
} else {
$this->comics[$index]['days'] = array($this->comics[$index]['days']);
}
}
if (is_array($this->comics[$index]['days'])) {
$this->comics[$index]['days'] = array_map(array($this, '_convertDay'), $this->comics[$index]['days']);
}
}
if (empty($this->comics[$index]['nohistory'])) {
$this->comics[$index]['nohistory'] = false;
}
}
}
开发者ID:raz0rsdge,项目名称:horde,代码行数:39,代码来源:Klutz.php
示例12: _buildQuery
protected function _buildQuery($params, $separator = '&', $noQuotes = true, $subList = false)
{
if (empty($params)) {
return '';
}
//encode both keys and values
$keys = $this->_encode(array_keys($params));
$values = $this->_encode(array_values($params));
$params = array_combine($keys, $values);
// Parameters are sorted by name, using lexicographical byte value ordering.
// http://oauth.net/core/1.0/#rfc.section.9.1.1
uksort($params, 'strcmp');
// Turn params array into an array of "key=value" strings
foreach ($params as $key => $value) {
if (is_array($value)) {
// If two or more parameters share the same name,
// they are sorted by their value. OAuth Spec: 9.1.1 (1)
natsort($value);
$params[$key] = $this->_buildQuery($value, $separator, $noQuotes, true);
continue;
}
if (!$noQuotes) {
$value = '"' . $value . '"';
}
$params[$key] = $value;
}
if ($subList) {
return $params;
}
foreach ($params as $key => $value) {
$params[$key] = $key . '=' . $value;
}
return implode($separator, $params);
}
开发者ID:brynner,项目名称:postr,代码行数:34,代码来源:base.php
示例13: _helper_apply_emoticons
/**
* Get a map between smiley codes and templates representing the HTML-image-code for this smiley. The smilies present of course depend on the forum involved.
*
* @param object Link to the real forum driver
* @param ?MEMBER Only emoticons the given member can see (NULL: don't care)
* @return array The map
*/
function _helper_apply_emoticons($this_ref, $member_id = NULL)
{
global $IN_MINIKERNEL_VERSION;
if ($IN_MINIKERNEL_VERSION == 1) {
return array();
}
$extra = '';
if (is_null($member_id)) {
global $EMOTICON_CACHE, $EMOTICON_LEVELS;
if (!is_null($EMOTICON_CACHE)) {
return $EMOTICON_CACHE;
}
} else {
$extra = has_specific_permission(get_member(), 'use_special_emoticons') ? '' : ' AND e_is_special=0';
}
$EMOTICON_CACHE = array();
$EMOTICON_LEVELS = array();
$query = 'SELECT e_code,e_theme_img_code,e_relevance_level FROM ' . $this_ref->connection->get_table_prefix() . 'f_emoticons WHERE e_relevance_level<4' . $extra;
if (strpos(get_db_type(), 'mysql') !== false) {
$query .= ' ORDER BY LENGTH(e_code) DESC';
}
$rows = $this_ref->connection->query($query);
foreach ($rows as $myrow) {
$tpl = 'EMOTICON_IMG_CODE_THEMED';
$EMOTICON_CACHE[$myrow['e_code']] = array($tpl, $myrow['e_theme_img_code'], $myrow['e_code']);
$EMOTICON_LEVELS[$myrow['e_code']] = $myrow['e_relevance_level'];
}
if (strpos(get_db_type(), 'mysql') === false) {
uksort($EMOTICON_CACHE, 'strlen_sort');
$EMOTICON_CACHE = array_reverse($EMOTICON_CACHE);
}
return $EMOTICON_CACHE;
}
开发者ID:erico-deh,项目名称:ocPortal,代码行数:40,代码来源:ocf_forum_driver_helper.php
示例14: build_http_query_multi
private function build_http_query_multi($params)
{
if (!$params) {
return '';
}
uksort($params, 'strcmp');
$pairs = array();
$this->boundary = $boundary = uniqid('------------------');
$MPboundary = '--' . $boundary;
$endMPboundary = $MPboundary . '--';
$multipartbody = '';
foreach ($params as $parameter => $value) {
if (in_array($parameter, array('pic', 'image')) && $value[0] == '@') {
$url = ltrim($value, '@');
$content = file_get_contents($url);
$array = explode('?', basename($url));
$filename = $array[0];
$body .= $MPboundary . "\r\n";
$body .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"' . "\r\n";
$body .= "Content-Type: image/unknown\r\n\r\n";
$body .= $content . "\r\n";
} else {
$body .= $MPboundary . "\r\n";
$body .= 'content-disposition: form-data; name="' . $parameter . "\"\r\n\r\n";
$body .= $value . "\r\n";
}
}
$multipartbody .= $endMPboundary;
return $multipartbody;
}
开发者ID:blackcocwhite,项目名称:quke8_wechat,代码行数:30,代码来源:wx.sdk.php
示例15: wp_generate_product_tag_cloud
function wp_generate_product_tag_cloud($tags, $args = '')
{
global $wp_rewrite;
$defaults = array('smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC');
$args = wp_parse_args($args, $defaults);
extract($args);
if (!$tags) {
return;
}
$counts = $tag_links = array();
foreach ((array) $tags as $tag) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_product_tag_link($tag->term_id);
if (is_wp_error($tag_links[$tag->name])) {
return $tag_links[$tag->name];
}
$tag_ids[$tag->name] = $tag->term_id;
}
$min_count = min($counts);
$spread = max($counts) - $min_count;
if ($spread <= 0) {
$spread = 1;
}
$font_spread = $largest - $smallest;
if ($font_spread <= 0) {
$font_spread = 1;
}
$font_step = $font_spread / $spread;
// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
if ('name' == $orderby) {
uksort($counts, 'strnatcasecmp');
} else {
asort($counts);
}
if ('DESC' == $order) {
$counts = array_reverse($counts, true);
}
$a = array();
$rel = is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ? ' rel="tag"' : '';
foreach ($counts as $tag => $count) {
$tag_id = $tag_ids[$tag];
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', ' ', wp_specialchars($tag));
$a[] = "<a href='{$tag_link}' class='tag-link-{$tag_id}' title='" . attribute_escape(sprintf(__('%d topics'), $count)) . "'{$rel} style='font-size: " . ($smallest + ($count - $min_count) * $font_step) . "{$unit};'>{$tag}</a>";
}
switch ($format) {
case 'array':
$return =& $a;
break;
case 'list':
$return = "<ul class='product_tag_cloud'>\n\t<li>";
$return .= join("</li>\n\t<li>", $a);
$return .= "</li>\n</ul>\n";
break;
default:
$return = join("\n", $a);
break;
}
return apply_filters('wp_generate_product_tag_cloud', $return, $tags, $args);
}
开发者ID:BGCX261,项目名称:zombie-craft-svn-to-git,代码行数:60,代码来源:tagging_functions.php
示例16: __construct
/**
* Constructor.
*/
public function __construct($idSite = false)
{
parent::__construct();
$this->jsClass = "SegmentSelectorControl";
$this->cssIdentifier = "segmentEditorPanel";
$this->cssClass = "piwikTopControl";
$this->idSite = $idSite ?: Common::getRequestVar('idSite', false, 'int');
$this->selectedSegment = Common::getRequestVar('segment', false, 'string');
$segments = APIMetadata::getInstance()->getSegmentsMetadata($this->idSite);
$segmentsByCategory = $customVariablesSegments = array();
foreach ($segments as $segment) {
if ($segment['category'] == Piwik::translate('General_Visit') && ($segment['type'] == 'metric' && $segment['segment'] != 'visitIp')) {
$metricsLabel = Piwik::translate('General_Metrics');
$metricsLabel[0] = strtolower($metricsLabel[0]);
$segment['category'] .= ' (' . $metricsLabel . ')';
}
$segmentsByCategory[$segment['category']][] = $segment;
}
uksort($segmentsByCategory, array($this, 'sortSegmentCategories'));
$this->createRealTimeSegmentsIsEnabled = Config::getInstance()->General['enable_create_realtime_segments'];
$this->segmentsByCategory = $segmentsByCategory;
$this->nameOfCurrentSegment = '';
$this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = 0;
$this->availableSegments = API::getInstance()->getAll($this->idSite);
foreach ($this->availableSegments as &$savedSegment) {
$savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']);
if (!empty($this->selectedSegment) && $this->selectedSegment == $savedSegment['definition']) {
$this->nameOfCurrentSegment = $savedSegment['name'];
$this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = $this->wouldApplySegment($savedSegment) ? 0 : 1;
}
}
$this->authorizedToCreateSegments = SegmentEditorAPI::getInstance()->isUserCanAddNewSegment($this->idSite);
$this->isUserAnonymous = Piwik::isUserIsAnonymous();
$this->segmentTranslations = $this->getTranslations();
}
开发者ID:carriercomm,项目名称:piwik,代码行数:38,代码来源:SegmentSelectorControl.php
示例17: toOptionArray
public function toOptionArray($isMultiselect = false)
{
if (!$this->_options) {
$countriesArray = Mage::getResourceModel('directory/country_collection')->load()->toOptionArray(false);
$this->_countries = array();
foreach ($countriesArray as $a) {
$this->_countries[$a['value']] = $a['label'];
}
$countryRegions = array();
$regionsCollection = Mage::getResourceModel('directory/region_collection')->load();
foreach ($regionsCollection as $region) {
$countryRegions[$region->getCountryId()][$region->getId()] = $region->getDefaultName();
}
uksort($countryRegions, array($this, 'sortRegionCountries'));
$this->_options = array();
foreach ($countryRegions as $countryId => $regions) {
$regionOptions = array();
foreach ($regions as $regionId => $regionName) {
$regionOptions[] = array('label' => $regionName, 'value' => $regionId);
}
$this->_options[] = array('label' => $this->_countries[$countryId], 'value' => $regionOptions);
}
}
$options = $this->_options;
if (!$isMultiselect) {
array_unshift($options, array('value' => '', 'label' => ''));
}
return $options;
}
开发者ID:barneydesmond,项目名称:propitious-octo-tribble,代码行数:29,代码来源:Allregion.php
示例18: getVariables
/**
* Get scope variables.
*
* @param boolean $showAll Include special variables (e.g. $_).
*
* @return array
*/
protected function getVariables($showAll)
{
$scopeVars = $this->context->getAll();
uksort($scopeVars, function ($a, $b) {
if ($a === '_e') {
return 1;
} elseif ($b === '_e') {
return -1;
} elseif ($a === '_') {
return 1;
} elseif ($b === '_') {
return -1;
} else {
// TODO: this should be natcasesort
return strcasecmp($a, $b);
}
});
$ret = array();
foreach ($scopeVars as $name => $val) {
if (!$showAll && in_array($name, self::$specialVars)) {
continue;
}
$ret[$name] = $val;
}
return $ret;
}
开发者ID:HarveyCheng,项目名称:myblog,代码行数:33,代码来源:VariableEnumerator.php
示例19: autocomplete_data
function autocomplete_data($query, $orderCallback)
{
//Will sort by $orderCallback and then ['name']
//You may wish to take $user by reference and add ['label'] and ['category'] to it
//Allows replacement-parameters too.
$args = func_get_args();
array_shift($args);
array_shift($args);
array_unshift($args, $query);
$data = call_user_func_array("DB::query", $args);
$results = array();
$order = array();
foreach ($data as &$datum) {
$order[] = $orderCallback($datum);
$results[] = $datum;
}
uksort($results, function ($ind1, $ind2) use($results, $order) {
//Sorts with respect to order specified in $order
if ($order[$ind1] == $order[$ind2]) {
//Sorts alphabetically within a category
if (array_key_exists("name", $results[$ind1])) {
return strcasecmp($results[$ind1]["name"], $results[$ind2]["name"]);
} else {
return 0;
}
} else {
//Uses the given ordering numbers to sort categories
return $order[$ind1] > $order[$ind2] ? 1 : -1;
}
});
return array_values($results);
//Reassigns keys, since uksort will maintain disordered numerical keys.
}
开发者ID:lhsmath,项目名称:lhsmath.org,代码行数:33,代码来源:functions.autocomplete.php
示例20: getTagWeights
public function getTagWeights($tags)
{
$tagWeights = array();
if (empty($tags))
return $tagWeights;
foreach ($tags as $tag)
{
$tagWeights[$tag] = (isset($tagWeights[$tag])) ? $tagWeights[$tag] + 1 : 1;
}
// Shuffle the tags
uksort($tagWeights, function() {
return rand() > rand();
});
$max = max($tagWeights);
// Max of 5 weights
$multiplier = ($max > 5) ? 5 / $max : 1;
foreach ($tagWeights as &$tag)
{
$tag = ceil($tag * $multiplier);
}
return $tagWeights;
}
开发者ID:artemzakholodilo,项目名称:blog,代码行数:26,代码来源:BlogRepository.php
注:本文中的uksort函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论