本文整理汇总了PHP中asort函数的典型用法代码示例。如果您正苦于以下问题:PHP asort函数的具体用法?PHP asort怎么用?PHP asort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了asort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterExample
public function afterExample(ExampleEvent $event)
{
$total = $this->stats->getEventsCount();
$counts = $this->stats->getCountsHash();
$percents = array_map(function ($count) use($total) {
return round($count / ($total / 100), 0);
}, $counts);
$lengths = array_map(function ($percent) {
return round($percent / 2, 0);
}, $percents);
$size = 50;
asort($lengths);
$progress = array();
foreach ($lengths as $status => $length) {
$text = $percents[$status] . '%';
$length = $size - $length >= 0 ? $length : $size;
$size = $size - $length;
if ($length > strlen($text) + 2) {
$text = str_pad($text, $length, ' ', STR_PAD_BOTH);
} else {
$text = str_pad('', $length, ' ');
}
$progress[$status] = sprintf("<{$status}-bg>%s</{$status}-bg>", $text);
}
krsort($progress);
$this->printException($event, 2);
$this->io->writeTemp(implode('', $progress) . ' ' . $total);
}
示例2: get_content
function get_content()
{
global $CFG, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
require_once $CFG->dirroot . '/course/lib.php';
$modinfo = get_fast_modinfo($course);
$modfullnames = array();
foreach ($modinfo->cms as $cm) {
if (!$cm->uservisible) {
continue;
}
$modfullnames[$cm->modname] = $cm->modplural;
}
asort($modfullnames, SORT_LOCALE_STRING);
foreach ($modfullnames as $modname => $modfullname) {
if ($modname != 'label') {
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $this->instance->pageid . '">' . $modfullname . '</a>';
$this->content->icons[] = '<img src="' . $CFG->modpixpath . '/' . $modname . '/icon.gif" class="icon" alt="" />';
}
}
return $this->content;
}
示例3: __construct
/**
* Import constructor.
*
* @param ContactService $contactService
* @param SelectionService $selectionService
*/
public function __construct(ContactService $contactService, SelectionService $selectionService)
{
parent::__construct();
$this->setAttribute('method', 'post');
$this->setAttribute('action', '');
$this->setAttribute('class', 'form-horizontal');
$selections = [];
foreach ($selectionService->findAll('selection') as $selection) {
/** @var $selection Selection */
if (is_null($selection->getSql())) {
$selections[$selection->getId()] = $selection->getSelection();
}
}
asort($selections);
$this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'selection_id', 'options' => ["value_options" => $selections, 'empty_option' => '-- Append to existing selection', "label" => "txt-append-to-selection", "help-block" => _("txt-contact-import-append-to-selection-name-help-block")]]);
$optins = [];
foreach ($contactService->findAll('optIn') as $optin) {
/** @var $optin OptIn */
$optins[$optin->getId()] = $optin->getOptIn();
}
asort($optins);
$this->add(['type' => '\\Zend\\Form\\Element\\MultiCheckbox', 'name' => 'optIn', 'options' => ["value_options" => $optins, "label" => "txt-select-opt-in", "help-block" => _("txt-contact-import-select-opt-in-help-block")]]);
$this->add(['type' => '\\Zend\\Form\\Element\\Text', 'name' => 'selection', 'options' => ["label" => "txt-selection", "help-block" => _("txt-contact-import-selection-name-help-block")]]);
$this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => ["label" => "txt-file", "help-block" => _("txt-contact-import-file-requirements")]]);
$this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'upload', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-verify-data")]]);
$this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'import', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-import")]]);
}
示例4: array_sort
function array_sort($array, $on, $order = SORT_ASC)
{
$new_array = array();
$sortable_array = array();
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $array[$k];
}
}
return $new_array;
}
示例5: preProcess
/**
* Function to pre processing
*
* @return None
* @access public
*/
function preProcess()
{
$this->_rgid = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0);
$this->_contactType = CRM_Utils_Request::retrieve('contact_type', 'String', $this, false, 0);
if ($this->_rgid) {
$rgDao =& new CRM_Dedupe_DAO_RuleGroup();
$rgDao->id = $this->_rgid;
$rgDao->find(true);
$this->_defaults['threshold'] = $rgDao->threshold;
$this->_contactType = $rgDao->contact_type;
$this->_defaults['level'] = $rgDao->level;
$this->_defaults['name'] = $rgDao->name;
$ruleDao =& new CRM_Dedupe_DAO_Rule();
$ruleDao->dedupe_rule_group_id = $this->_rgid;
$ruleDao->find();
$count = 0;
while ($ruleDao->fetch()) {
$this->_defaults["where_{$count}"] = "{$ruleDao->rule_table}.{$ruleDao->rule_field}";
$this->_defaults["length_{$count}"] = $ruleDao->rule_length;
$this->_defaults["weight_{$count}"] = $ruleDao->rule_weight;
$count++;
}
}
$supported =& CRM_Dedupe_BAO_RuleGroup::supportedFields($this->_contactType);
if (is_array($supported)) {
foreach ($supported as $table => $fields) {
foreach ($fields as $field => $title) {
$this->_fields["{$table}.{$field}"] = $title;
}
}
}
asort($this->_fields);
}
示例6: __construct
/**
*/
public function __construct()
{
$this->_rollup = 'WITH ROLLUP';
$this->_autoIncludeIndexedFieldsAsOrderBys = 1;
$yearsInPast = 10;
$yearsInFuture = 1;
$date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, $yearsInFuture);
$count = $date['maxYear'];
while ($date['minYear'] <= $count) {
$optionYear[$date['minYear']] = $date['minYear'];
$date['minYear']++;
}
// Check if CiviCampaign is a) enabled and b) has active campaigns
$config = CRM_Core_Config::singleton();
$campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
if ($campaignEnabled) {
$getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
$this->activeCampaigns = $getCampaigns['campaigns'];
asort($this->activeCampaigns);
}
$this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'grouping' => 'contact-field', 'fields' => array('sort_name' => array('title' => ts('Donor Name'), 'required' => TRUE), 'first_name' => array('title' => ts('First Name')), 'middle_name' => array('title' => ts('Middle Name')), 'last_name' => array('title' => ts('Last Name')), 'id' => array('no_display' => TRUE, 'required' => TRUE), 'gender_id' => array('title' => ts('Gender')), 'birth_date' => array('title' => ts('Birth Date')), 'age' => array('title' => ts('Age'), 'dbAlias' => 'TIMESTAMPDIFF(YEAR, contact_civireport.birth_date, CURDATE())'), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name'), 'default' => '1', 'default_weight' => '0', 'default_order' => 'ASC'), 'first_name' => array('name' => 'first_name', 'title' => ts('First Name')), 'gender_id' => array('name' => 'gender_id', 'title' => ts('Gender')), 'birth_date' => array('name' => 'birth_date', 'title' => ts('Birth Date')), 'age_at_event' => array('name' => 'age_at_event', 'title' => ts('Age at Event')), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype'))), 'filters' => array('sort_name' => array('title' => ts('Donor Name'), 'operator' => 'like'), 'id' => array('title' => ts('Contact ID'), 'no_display' => TRUE), 'gender_id' => array('title' => ts('Gender'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id')), 'birth_date' => array('title' => ts('Birth Date'), 'operatorType' => CRM_Report_Form::OP_DATE), 'contact_type' => array('title' => ts('Contact Type')), 'contact_sub_type' => array('title' => ts('Contact Subtype')))), 'civicrm_line_item' => array('dao' => 'CRM_Price_DAO_LineItem'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'grouping' => 'contact-field', 'fields' => array('email' => array('title' => ts('Email'), 'default' => TRUE))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'grouping' => 'contact-field', 'fields' => array('phone' => array('title' => ts('Phone'), 'default' => TRUE))));
$this->_columns += $this->addAddressFields();
$this->_columns += array('civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('contact_id' => array('title' => ts('contactId'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'total_amount' => array('title' => ts('Total Amount'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE), 'receive_date' => array('title' => ts('Year'), 'no_display' => TRUE, 'required' => TRUE, 'no_repeat' => TRUE)), 'filters' => array('yid' => array('name' => 'receive_date', 'title' => ts('This Year'), 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $optionYear, 'default' => date('Y'), 'type' => CRM_Utils_Type::T_INT), 'financial_type_id' => array('title' => ts('Financial Type'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes()), 'contribution_status_id' => array('title' => ts('Contribution Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Contribute_PseudoConstant::contributionStatus(), 'default' => array('1')))));
// If we have a campaign, build out the relevant elements
if ($campaignEnabled && !empty($this->activeCampaigns)) {
$this->_columns['civicrm_contribution']['fields']['campaign_id'] = array('title' => ts('Campaign'), 'default' => 'false');
$this->_columns['civicrm_contribution']['filters']['campaign_id'] = array('title' => ts('Campaign'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->activeCampaigns, 'type' => CRM_Utils_Type::T_INT);
}
$this->_groupFilter = TRUE;
$this->_tagFilter = TRUE;
parent::__construct();
}
示例7: __construct
public function __construct(&$vars, $title = '')
{
global $conf;
parent::__construct($vars, $title);
$this->addHidden('', 'id', 'int', true, true);
if (!$GLOBALS['registry']->getAuth()) {
$this->addVariable(_("Your Email Address"), 'user_email', 'email', true);
if (!empty($conf['guests']['captcha'])) {
$this->addVariable(_("Spam protection"), 'captcha', 'figlet', true, null, null, array(Whups::getCAPTCHA(!$this->isSubmitted()), $conf['guests']['figlet_font']));
}
}
$this->addVariable(_("Comment"), 'newcomment', 'longtext', false);
$this->addVariable(_("Attachment"), 'newattachment', 'file', false);
$this->addVariable(_("Watch this ticket"), 'add_watch', 'boolean', false);
/* Group restrictions. */
if ($GLOBALS['registry']->isAdmin(array('permission' => 'whups:admin')) || $GLOBALS['injector']->getInstance('Horde_Perms')->hasPermission('whups:hiddenComments', $GLOBALS['registry']->getAuth(), Horde_Perms::EDIT)) {
$groups = $GLOBALS['injector']->getInstance('Horde_Group');
$mygroups = $groups->listGroups($GLOBALS['registry']->getAuth());
if ($mygroups) {
foreach (array_keys($mygroups) as $gid) {
$grouplist[$gid] = $groups->getName($gid, true);
}
asort($grouplist);
$grouplist = array_merge(array(0 => _("This comment is visible to everyone")), $grouplist);
$this->addVariable(_("Make this comment visible only to members of a group?"), 'group', 'enum', true, false, null, array($grouplist));
}
}
}
示例8: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
$this->_mapperFields = $this->get('fields');
unset($this->_mapperFields['id']);
asort($this->_mapperFields);
$this->_columnCount = $this->get('columnCount');
$this->assign('columnCount', $this->_columnCount);
$this->_dataValues = $this->get('dataValues');
$this->assign('dataValues', $this->_dataValues);
$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
if ($skipColumnHeader) {
$this->assign('skipColumnHeader', $skipColumnHeader);
$this->assign('rowDisplayCount', 3);
/* if we had a column header to skip, stash it for later */
$this->_columnHeaders = $this->_dataValues[0];
} else {
$this->assign('rowDisplayCount', 2);
}
$highlightedFields = array();
$requiredFields = array('activity_date_time', 'activity_type_id', 'activity_label', 'target_contact_id', 'activity_subject');
foreach ($requiredFields as $val) {
$highlightedFields[] = $val;
}
$this->assign('highlightedFields', $highlightedFields);
}
示例9: liste_modeles
/**
* Load into memory list of available export format
*
* @param DoliDB $db Database handler
* @param integer $maxfilenamelength Max length of value to show
* @return array List of templates (same content than array this->driverlabel)
*/
function liste_modeles($db, $maxfilenamelength = 0)
{
dol_syslog(get_class($this) . "::liste_modeles");
$dir = DOL_DOCUMENT_ROOT . "/core/modules/export/";
$handle = opendir($dir);
// Recherche des fichiers drivers exports disponibles
$var = True;
$i = 0;
if (is_resource($handle)) {
while (($file = readdir($handle)) !== false) {
if (preg_match("/^export_(.*)\\.modules\\.php\$/i", $file, $reg)) {
$moduleid = $reg[1];
// Chargement de la classe
$file = $dir . "/export_" . $moduleid . ".modules.php";
$classname = "Export" . ucfirst($moduleid);
require_once $file;
$module = new $classname($db);
// Picto
$this->picto[$module->id] = $module->picto;
// Driver properties
$this->driverlabel[$module->id] = $module->getDriverLabel() . (empty($module->disabled) ? '' : ' __(Disabled)__');
// '__(Disabled)__' is a key
$this->driverdesc[$module->id] = $module->getDriverDesc();
$this->driverversion[$module->id] = $module->getDriverVersion();
// If use an external lib
$this->liblabel[$module->id] = $module->getLibLabel();
$this->libversion[$module->id] = $module->getLibVersion();
$i++;
}
}
closedir($handle);
}
asort($this->driverlabel);
return $this->driverlabel;
}
示例10: afg_get_sets_groups_galleries
function afg_get_sets_groups_galleries(&$photosets_map, &$groups_map, &$galleries_map, $user_id)
{
global $pf;
$rsp_obj = $pf->photosets_getList($user_id);
if (!$pf->error_code) {
foreach ($rsp_obj['photoset'] as $photoset) {
$photosets_map[$photoset['id']] = $photoset['title']['_content'];
}
}
$rsp_obj = $pf->galleries_getList($user_id);
if (!$pf->error_code) {
foreach ($rsp_obj['galleries']['gallery'] as $gallery) {
$galleries_map[$gallery['id']] = $gallery['title']['_content'];
}
}
if (get_option('afg_flickr_token')) {
$rsp_obj = $pf->groups_pools_getGroups();
if (!$pf->error_code) {
foreach ($rsp_obj['group'] as $group) {
$groups_map[$group['nsid']] = $group['name'];
}
}
} else {
$rsp_obj = $pf->people_getPublicGroups($user_id);
if (!$pf->error_code) {
foreach ($rsp_obj as $group) {
$groups_map[$group['nsid']] = $group['name'];
}
}
}
asort($photosets_map);
asort($groups_map);
asort($galleries_map);
}
示例11: _cacheMiss
function _cacheMiss($cache, $id)
{
$allLanguages =& Registry::get('allLanguages-' . $cache->cacheId, true, null);
if ($allLanguages === null) {
// Add a locale load to the debug notes.
$notes =& Registry::get('system.debug.notes');
$locale = $cache->cacheId;
if ($locale == null) {
$locale = AppLocale::getLocale();
}
$filename = $this->getLanguageFilename($locale);
$notes[] = array('debug.notes.languageListLoad', array('filename' => $filename));
// Reload locale registry file
$xmlDao = new XMLDAO();
$data = $xmlDao->parseStruct($filename, array('language'));
// Build array with ($charKey => array(stuff))
if (isset($data['language'])) {
foreach ($data['language'] as $languageData) {
$allLanguages[$languageData['attributes']['code']] = array($languageData['attributes']['name']);
}
}
if (is_array($allLanguages)) {
asort($allLanguages);
}
$cache->setEntireCache($allLanguages);
}
if (isset($allLanguages[$id])) {
return $allLanguages[$id];
} else {
return null;
}
}
示例12: ArraySortBy
function ArraySortBy($Array, $ValueKey, $SortFlag = SORT_NUMERIC, $Reverse = false, $DefaultValue = NULL)
{
$Keys = array();
if (is_array($ValueKey)) {
$ValueFunction = $ValueKey[1];
$ValueKey = $ValueKey[0];
}
foreach ($Array as $Key => $SubArray) {
if (is_array($SubArray)) {
if (array_key_exists($ValueKey, $SubArray)) {
if (isset($ValueFunction)) {
$Keys[$Key] = $ValueFunction($SubArray[$ValueKey]);
} else {
$Keys[$Key] = $SubArray[$ValueKey];
}
} else {
$Keys[$Key] = $DefaultValue;
}
}
}
if ($Reverse) {
arsort($Keys, $SortFlag);
} else {
asort($Keys, $SortFlag);
}
$Result = array();
foreach ($Keys as $Key => $Value) {
$Result[] = $Array[$Key];
}
return $Result;
}
示例13: renderEditControl
public function renderEditControl(array $handles)
{
$engines = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorApplicationSearchEngine')->loadObjects();
$value = $this->getFieldValue();
$queries = array();
$seen = false;
foreach ($engines as $engine_class => $engine) {
$engine->setViewer($this->getViewer());
$engine_queries = $engine->loadEnabledNamedQueries();
$query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey');
asort($query_map);
foreach ($query_map as $key => $name) {
$queries[$engine_class][] = array('key' => $key, 'name' => $name);
if ($key == $value) {
$seen = true;
}
}
}
if (strlen($value) && !$seen) {
$name = pht('Custom Query ("%s")', $value);
} else {
$name = pht('(None)');
}
$options = array($value => $name);
$app_control_key = $this->getFieldConfigValue('control.application');
Javelin::initBehavior('dashboard-query-panel-select', array('applicationID' => $this->getFieldControlID($app_control_key), 'queryID' => $this->getFieldControlID(), 'options' => $queries, 'value' => array('key' => strlen($value) ? $value : null, 'name' => $name)));
return id(new AphrontFormSelectControl())->setID($this->getFieldControlID())->setLabel($this->getFieldName())->setCaption($this->getCaption())->setName($this->getFieldKey())->setValue($this->getFieldValue())->setOptions($options);
}
示例14: init
public function init()
{
//cached data not outdated?
$this->events = $this->pdc->get('pdh_calendar_events_table.events');
$this->repeatable_events = $this->pdc->get('pdh_calendar_events_table.repeatable');
$this->event_timestamps = $this->pdc->get('pdh_calendar_events_table.timestamps');
if ($this->events !== NULL && $this->repeatable_events !== NULL && $this->event_timestamps !== NULL) {
return true;
}
$objQuery = $this->db->query("SELECT * FROM __calendar_events");
if ($objQuery) {
while ($row = $objQuery->fetchAssoc()) {
$this->events[$row['id']] = array('id' => (int) $row['id'], 'calendar_id' => (int) $row['calendar_id'], 'name' => $row['name'], 'creator' => (int) $row['creator'], 'timestamp_start' => (int) $row['timestamp_start'], 'timestamp_end' => (int) $row['timestamp_end'], 'allday' => (int) $row['allday'], 'private' => (int) $row['private'], 'visible' => (int) $row['visible'], 'closed' => (int) $row['closed'], 'notes' => $row['notes'], 'repeating' => (int) $row['repeating'], 'cloneid' => (int) $row['cloneid'], 'timezone' => $row['timezone']);
$this->events[$row['id']]['extension'] = unserialize($row['extension']);
$this->event_timestamps[$row['id']] = (int) $row['timestamp_start'];
// set the repeatable array
if ((int) $row['repeating'] > 0) {
$parentid = (int) $row['cloneid'] > 0 ? (int) $row['cloneid'] : (int) $row['id'];
$this->repeatable_events[$parentid][] = (int) $row['id'];
}
}
// sort the timestamps
if (is_array($this->event_timestamps)) {
asort($this->event_timestamps);
}
// set the cache
$this->pdc->put('pdh_calendar_events_table.events', $this->events, null);
$this->pdc->put('pdh_calendar_events_table.repeatable', $this->repeatable_events, null);
$this->pdc->put('pdh_calendar_events_table.timestamps', $this->event_timestamps, null);
}
}
示例15: normalize
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = [])
{
$data = parent::normalize($object, $format, $context);
asort($data['attributes']);
$data['attributes'] = implode(',', $data['attributes']);
return $data;
}