本文整理汇总了PHP中usort函数的典型用法代码示例。如果您正苦于以下问题:PHP usort函数的具体用法?PHP usort怎么用?PHP usort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了usort函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: tearDownAfterClass
public static function tearDownAfterClass()
{
if (!self::$timing) {
echo "\n";
return;
}
$class = get_called_class();
echo "Timing results : {$class}\n";
$s = sprintf("%40s %6s %9s %9s %4s\n", 'name', 'count', 'total', 'avg', '% best');
echo str_repeat('=', strlen($s)) . "\n";
echo $s;
echo str_repeat('-', strlen($s)) . "\n";
array_walk(self::$timing, function (&$value, $key) {
$value['avg'] = round($value['total'] / $value['count'] * 1000000, 3);
});
usort(self::$timing, function ($a, $b) {
$at = $a['avg'];
$bt = $b['avg'];
return $at === $bt ? 0 : ($at < $bt ? -1 : 1);
});
$best = self::$timing[0]['avg'];
foreach (self::$timing as $timing) {
printf("%40s %6d %7.3fms %7.3fus %4.1f%%\n", $timing['name'], $timing['count'], round($timing['total'] * 1000, 3), $timing['avg'], round($timing['avg'] / $best * 100, 3));
}
echo str_repeat('-', strlen($s)) . "\n\n";
printf("\nTiming compensated for avg overhead for: timeIt of %.3fus and startTimer/endTimer of %.3fus per invocation\n\n", self::$timeItOverhead * 1000000, self::$startEndOverhead * 1000000);
parent::tearDownAfterClass();
}
开发者ID:mean-cj,项目名称:laravel-translation-manager,代码行数:28,代码来源:TranslationManagerTestCase.php
示例2: getAllProjects
public function getAllProjects()
{
$key = "{$this->cachePrefix}-all-projects";
if ($this->cache && ($projects = $this->cache->fetch($key))) {
return $projects;
}
$first = json_decode($this->client->get('projects.json', ['query' => ['limit' => 100]])->getBody(), true);
$projects = $first['projects'];
if ($first['total_count'] > 100) {
$requests = [];
for ($i = 100; $i < $first['total_count']; $i += 100) {
$requests[] = $this->client->getAsync('projects.json', ['query' => ['limit' => 100, 'offset' => $i]]);
}
/** @var Response[] $responses */
$responses = Promise\unwrap($requests);
$responseProjects = array_map(function (Response $response) {
return json_decode($response->getBody(), true)['projects'];
}, $responses);
$responseProjects[] = $projects;
$projects = call_user_func_array('array_merge', $responseProjects);
}
usort($projects, function ($projectA, $projectB) {
return strcasecmp($projectA['name'], $projectB['name']);
});
$this->cache && $this->cache->save($key, $projects);
return $projects;
}
开发者ID:stelsvitya,项目名称:server-manager,代码行数:27,代码来源:Projects.php
示例3: cleanOldExecutions
/**
*
* @return boolean
*/
public function cleanOldExecutions()
{
$em = $this->getEntityManager();
$processes = $em->getRepository('Minibus\\Model\\Entity\\Process')->findAll();
foreach ($processes as $process) {
$executions = $process->getExecutions();
if ($executions instanceof \Doctrine\ORM\PersistentCollection) {
$count = $executions->count();
$numberToDelete = $count - $this->getNumberToKeep();
$first = true;
$executions = $executions->toArray();
usort($executions, function (Execution $e1, Execution $e2) {
return $e2->getId() > $e1->getId();
});
foreach ($executions as $execution) {
$count--;
// Si une exécution est encours, si ce n'est pas la première exécution d'un process
// en cours on l'arrête.
if ((false === $process->getRunning() || false === $first) && $execution->getState() == Execution::RUNNING_STATE) {
$execution->setState(Execution::STOPPED_STATE);
}
if ($count <= $numberToDelete) {
$em->remove($execution);
$execution->getProcess()->removeExecution($execution);
}
$first = false;
}
}
}
$em->flush();
}
开发者ID:dsi-agpt,项目名称:minibus,代码行数:35,代码来源:ProcessUpdater.php
示例4: registerLocator
/**
* @param ResourceLocatorInterface $locator
*/
public function registerLocator(ResourceLocatorInterface $locator)
{
$this->locators[] = $locator;
@usort($this->locators, function ($locator1, $locator2) {
return $locator2->getPriority() - $locator1->getPriority();
});
}
开发者ID:focuslife,项目名称:v0.1,代码行数:10,代码来源:ResourceManager.php
示例5: getLatestSymfonyVersion
private function getLatestSymfonyVersion()
{
// Get GitHub JSON request
$opts = array('http' => array('method' => "GET", 'header' => "User-Agent: LiipMonitorBundle\r\n"));
$context = stream_context_create($opts);
$githubUrl = 'https://api.github.com/repos/symfony/symfony/tags';
$githubJSONResponse = file_get_contents($githubUrl, false, $context);
// Convert it to a PHP object
$githubResponseArray = json_decode($githubJSONResponse, true);
if (empty($githubResponseArray)) {
throw new \Exception("No valid response or no tags received from GitHub.");
}
$tags = array();
foreach ($githubResponseArray as $tag) {
$tags[] = $tag['name'];
}
// Sort tags
usort($tags, "version_compare");
// Filter out non final tags
$filteredTagList = array_filter($tags, function ($tag) {
return !stripos($tag, "PR") && !stripos($tag, "RC") && !stripos($tag, "BETA");
});
// The first one is the last stable release for Symfony 2
$reverseFilteredTagList = array_reverse($filteredTagList);
return str_replace("v", "", $reverseFilteredTagList[0]);
}
开发者ID:jshedde,项目名称:LiipMonitorBundle,代码行数:26,代码来源:SymfonyVersion.php
示例6: search_doc_files
function search_doc_files($s)
{
$a = get_app();
$itemspage = get_pconfig(local_channel(), 'system', 'itemspage');
App::set_pager_itemspage(intval($itemspage) ? $itemspage : 20);
$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
$regexop = db_getfunc('REGEXP');
$r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and\n\t\tbody {$regexop} '%s' and item_type = %d {$pager_sql}", dbesc($s), intval(ITEM_TYPE_DOC));
$r = fetch_post_tags($r, true);
for ($x = 0; $x < count($r); $x++) {
$r[$x]['text'] = $r[$x]['body'];
$r[$x]['rank'] = 0;
if ($r[$x]['term']) {
foreach ($r[$x]['term'] as $t) {
if (stristr($t['term'], $s)) {
$r[$x]['rank']++;
}
}
}
if (stristr($r[$x]['sid'], $s)) {
$r[$x]['rank']++;
}
$r[$x]['rank'] += substr_count(strtolower($r[$x]['text']), strtolower($s));
// bias the results to the observer's native language
if ($r[$x]['lang'] === App::$language) {
$r[$x]['rank'] = $r[$x]['rank'] + 10;
}
}
usort($r, 'doc_rank_sort');
return $r;
}
开发者ID:anmol26s,项目名称:hubzilla-yunohost,代码行数:31,代码来源:help.php
示例7: load
/**
* Load the fixture jobs in database
*
* @return null
*/
public function load()
{
$rawJobs = array();
$fileLocator = $this->container->get('file_locator');
foreach ($this->jobsFilePaths as $jobsFilePath) {
$realPath = $fileLocator->locate('@' . $jobsFilePath);
$this->reader->setFilePath($realPath);
// read the jobs list
while ($rawJob = $this->reader->read()) {
$rawJobs[] = $rawJob;
}
// sort the jobs by order
usort($rawJobs, function ($item1, $item2) {
if ($item1['order'] === $item2['order']) {
return 0;
}
return $item1['order'] < $item2['order'] ? -1 : 1;
});
}
// store the jobs
foreach ($rawJobs as $rawJob) {
unset($rawJob['order']);
$job = $this->processor->process($rawJob);
$config = $job->getRawConfiguration();
$config['filePath'] = sprintf('%s/%s', $this->installerDataPath, $config['filePath']);
$job->setRawConfiguration($config);
$this->em->persist($job);
}
$this->em->flush();
}
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:35,代码来源:FixtureJobLoader.php
示例8: run
public function run() {
$typeName = $this->defaultType;
$categoryId = intval($this->getInput('categoryid','get'));
$alias = $this->getInput('alias','get');
$tagServicer = $this->_getTagService();
$hotTags = $tagServicer->getHotTags($categoryId,20);
$tagIds = array();
foreach ($hotTags as $k => $v) {
$attentions = $this->_getTagAttentionDs()->getAttentionUids($k,0,5);
$hotTags[$k]['weight'] = 0.7 * $v['content_count'] + 0.3 * $v['attention_count'];
$hotTags[$k]['attentions'] = array_keys($attentions);
$tagIds[] = $k;
}
usort($hotTags, array($this, 'cmp'));
$myTags = $this->_getTagAttentionDs()->getAttentionByUidAndTagsIds($this->loginUser->uid,$tagIds);
$this->setOutput($myTags, 'myTags');
$this->setOutput($hotTags, 'hotTags');
$this->setOutput($categoryId, 'categoryId');
//seo设置
Wind::import('SRV:seo.bo.PwSeoBo');
$seoBo = PwSeoBo::getInstance();
$seoBo->init('topic', 'hot');
Wekit::setV('seo', $seoBo);
}
开发者ID:healthguo,项目名称:PHP,代码行数:27,代码来源:IndexController.php
示例9: scan
function scan($dir)
{
$files = array();
// Is there actually such a folder/file?
if (file_exists($dir)) {
$scanned = scandir($dir);
//get a directory listing
$scanned = array_diff(scandir($dir), array('.', '..', '.DS_Store', 'Thumbs.db'));
//sort folders first, then by type, then alphabetically
usort($scanned, create_function('$a,$b', '
return is_dir ($a)
? (is_dir ($b) ? strnatcasecmp ($a, $b) : -1)
: (is_dir ($b) ? 1 : (
strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION)) == 0
? strnatcasecmp ($a, $b)
: strcasecmp (pathinfo ($a, PATHINFO_EXTENSION), pathinfo ($b, PATHINFO_EXTENSION))
))
;
'));
foreach ($scanned as $f) {
if (!$f || $f[0] == '.') {
continue;
// Ignore hidden files
}
if (is_dir($dir . '/' . $f)) {
// The path is a folder
$files[] = array("name" => $f, "type" => "folder", "path" => $dir . '/' . $f, "items" => scan($dir . '/' . $f));
} else {
// It is a file
$files[] = array("name" => $f, "type" => "file", "ext" => pathinfo($f, PATHINFO_EXTENSION), "path" => $dir . '/' . $f, "size" => filesize($dir . '/' . $f));
}
}
}
return $files;
}
开发者ID:vkynchev,项目名称:KynchevIDE,代码行数:35,代码来源:scan.php
示例10: registerMaintainer
/**
* @param Maintainer\MaintainerInterface $maintainer
*/
public function registerMaintainer(Maintainer\MaintainerInterface $maintainer)
{
$this->maintainers[] = $maintainer;
@usort($this->maintainers, function ($maintainer1, $maintainer2) {
return $maintainer2->getPriority() - $maintainer1->getPriority();
});
}
开发者ID:ProgrammingPeter,项目名称:nba-schedule-api,代码行数:10,代码来源:ExampleRunner.php
示例11: siteSidebar
public function siteSidebar()
{
global $Language;
global $dbTags;
global $Url;
$db = $dbTags->db['postsIndex'];
$filter = $Url->filters('tag');
$html = '<div class="plugin plugin-tags">';
$html .= '<h2>' . $this->getDbField('label') . '</h2>';
$html .= '<div class="plugin-content">';
$html .= '<ul>';
$tagArray = array();
foreach ($db as $tagKey => $fields) {
$tagArray[] = array('tagKey' => $tagKey, 'count' => $dbTags->countPostsByTag($tagKey), 'name' => $fields['name']);
}
// Sort the array based on options
if ($this->getDbField('sort') == "count") {
usort($tagArray, function ($a, $b) {
return $b['count'] - $a['count'];
});
} elseif ($this->getDbField('sort') == "alpha") {
usort($tagArray, function ($a, $b) {
return strcmp($a['tagKey'], $b['tagKey']);
});
}
foreach ($tagArray as $tagKey => $fields) {
// Print the parent
$html .= '<li><a href="' . HTML_PATH_ROOT . $filter . '/' . $fields['tagKey'] . '">' . $fields['name'] . ' (' . $fields['count'] . ')</a></li>';
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
开发者ID:vorons,项目名称:bludit,代码行数:34,代码来源:plugin.php
示例12: Form
function Form()
{
$rgb = new RGB();
$this->iColors = array_keys($rgb->rgb_table);
usort($this->iColors, '_cmp');
$this->iGradstyles = array("Vertical", 2, "Horizontal", 1, "Vertical from middle", 3, "Horizontal from middle", 4, "Horizontal wider middle", 6, "Vertical wider middle", 7, "Rectangle", 5);
}
开发者ID:hcvcastro,项目名称:pxp,代码行数:7,代码来源:mkgrad.php
示例13: init
public function init()
{
// collect tables
foreach ($this->node->xpath("value") as $key => $node) {
$table = $this->getDocument()->getFormatter()->createTable($this, $node);
// skip translation tables
if ($table->isTranslationTable()) {
continue;
}
$this->tables[] = $table;
}
usort($this->tables, function ($a, $b) {
return strcmp($a->getModelName(), $b->getModelName());
});
/*
* before you can check for foreign keys
* you have to store at first all tables in the
* object registry
*/
foreach ($this->tables as $table) {
$table->initIndices();
$table->initForeignKeys();
}
// initialize many to many relation
if ($this->getDocument()->getConfig()->get(FormatterInterface::CFG_ENHANCE_M2M_DETECTION)) {
foreach ($this->tables as $table) {
$table->initManyToManyRelations();
}
}
}
开发者ID:codifico,项目名称:mysql-workbench-schema-exporter,代码行数:30,代码来源:Tables.php
示例14: show_news
public static function show_news($folder = 'posts', $template = 'templates')
{
$m = new Mustache_Engine();
$files = glob("{$folder}/*.md");
/** /
usort($files, function($a, $b) {
return filemtime($a) < filemtime($b);
});
/**/
$html = '';
foreach ($files as $file) {
$route = substr($file, strlen($folder) + 1, -3);
$page = new FrontMatter($file);
$title = $page->fetch('title') != '' ? $page->fetch('title') : $route;
$date = $page->fetch('date');
$author = $page->fetch('author');
$description = $page->fetch('description') == '' ? '' : $page->fetch('description');
$data[] = array('title' => $title, 'route' => $route, 'author' => $author, 'description' => $description, 'date' => $date);
}
/**/
function date_compare($a, $b)
{
$t1 = strtotime($a['date']);
$t2 = strtotime($b['date']);
return $t1 - $t2;
}
usort($data, 'date_compare');
$data = array_reverse($data);
/**/
$template = file_get_contents('templates/show_news.tpl');
$data['files'] = $data;
return $m->render($template, $data);
return $html;
}
开发者ID:modularr,项目名称:markpresslib,代码行数:34,代码来源:MarkPressLib.php
示例15: registerClassPatch
/**
* Registers new class patch.
*
* @param ClassPatchInterface $patch
*/
public function registerClassPatch(ClassPatchInterface $patch)
{
$this->patches[] = $patch;
@usort($this->patches, function (ClassPatchInterface $patch1, ClassPatchInterface $patch2) {
return $patch2->getPriority() - $patch1->getPriority();
});
}
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:12,代码来源:Doubler.php
示例16: generateContent
protected function generateContent($templatePath, $contentType)
{
// We build these into a single string so that we can deploy this resume as a
// single file.
$assetPath = join(DIRECTORY_SEPARATOR, array($templatePath, $contentType));
if (!file_exists($assetPath)) {
return '';
}
$assets = array();
// Our PHAR deployment can't handle the GlobAsset typically used here
foreach (new \DirectoryIterator($assetPath) as $fileInfo) {
if ($fileInfo->isDot() || !$fileInfo->isFile()) {
continue;
}
array_push($assets, new FileAsset($fileInfo->getPathname()));
}
usort($assets, function (FileAsset $a, FileAsset $b) {
return strcmp($a->getSourcePath(), $b->getSourcePath());
});
$collection = new AssetCollection($assets);
switch ($contentType) {
case 'css':
$collection->ensureFilter(new Filter\LessphpFilter());
break;
}
return $collection->dump();
}
开发者ID:regothic,项目名称:markdown-resume,代码行数:27,代码来源:HtmlCommand.php
示例17: getVenuesSortedByPrice
/**
* @return array of \app\model\Venue ascending by price
*/
public function getVenuesSortedByPrice()
{
usort($this->venues, function ($venueA, $venueB) {
return $venueA->getPrice() > $venueB->getPrice();
});
return $this->venues;
}
开发者ID:kk222hk,项目名称:1dv608-laborations,代码行数:10,代码来源:VenueList.php
示例18: display_page
public function display_page(Page $page, SetupPanel $panel)
{
$setupblock_html1 = "";
$setupblock_html2 = "";
usort($panel->blocks, "blockcmp");
/*
* Try and keep the two columns even; count the line breaks in
* each an calculate where a block would work best
*/
$len1 = 0;
$len2 = 0;
foreach ($panel->blocks as $block) {
if ($block instanceof SetupBlock) {
$html = $this->sb_to_html($block);
$len = count(explode("<br>", $html)) + 1;
if ($len1 <= $len2) {
$setupblock_html1 .= $this->sb_to_html($block);
$len1 += $len;
} else {
$setupblock_html2 .= $this->sb_to_html($block);
$len2 += $len;
}
}
}
$table = "\n\t\t\t<form action='" . make_link("setup/save") . "' method='POST'><table>\n\t\t\t<tr><td>{$setupblock_html1}</td><td>{$setupblock_html2}</td></tr>\n\t\t\t<tr><td colspan='2'><input type='submit' value='Save Settings'></td></tr>\n\t\t\t</table></form>\n\t\t\t";
$page->set_title("Shimmie Setup");
$page->set_heading("Shimmie Setup");
$page->add_block(new Block("Navigation", $this->build_navigation(), "left", 0));
$page->add_block(new Block("Setup", $table));
}
开发者ID:kmcasto,项目名称:shimmie2,代码行数:30,代码来源:theme.php
示例19: get_suggestions
/**
*
* Returns array of people containing entity, mutuals (friends), groups (shared) and priority
* @param Int $guid
* @param Int $friends_limit
* @param Int $groups_limit
* @return Array
*/
function get_suggestions($guid, $friends_of_friends_limit = 10, $groups_members_limit = 10)
{
$dbprefix = elgg_get_config('dbprefix');
$guid = sanitize_int($guid);
$suggestions = array();
if ($friends_of_friends_limit) {
// get some friends of friends
$options = array('selects' => array('COUNT(fof.guid_two) as priority'), 'type' => 'user', 'joins' => array("JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid", "JOIN {$dbprefix}entity_relationships fr ON fr.guid_one = {$guid} AND fr.relationship = 'friend'", "JOIN {$dbprefix}entity_relationships fof ON fof.guid_one = fr.guid_two AND fof.relationship = 'friend'"), "wheres" => array("ue.banned = 'no'", "e.guid NOT IN (SELECT f.guid_two FROM {$dbprefix}entity_relationships f WHERE f.guid_one = {$guid} AND f.relationship = 'friend')", "fof.guid_two = e.guid", "e.guid != {$guid}"), 'group_by' => 'e.guid', 'order_by' => 'priority desc, ue.last_action desc', 'limit' => abs((int) $friends_of_friends_limit));
$fof = elgg_get_entities($options);
foreach ($fof as $f) {
$priority = (int) $f->getVolatileData('select:priority');
$suggestions[$f->guid] = array('entity' => $f, 'mutuals' => $priority, 'groups' => 0, 'priority' => $priority);
}
}
if ($groups_members_limit) {
// get some mutual group members
$options = array('selects' => array('COUNT(mog.guid_two) as priority'), 'type' => 'user', 'joins' => array("JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid", "JOIN {$dbprefix}entity_relationships g ON g.guid_one = {$guid} AND g.relationship = 'member'", "JOIN {$dbprefix}groups_entity ge ON ge.guid = g.guid_two", "JOIN {$dbprefix}entity_relationships mog ON mog.guid_two = g.guid_two AND mog.relationship = 'member'"), "wheres" => array("ue.banned = 'no'", "e.guid NOT IN (SELECT f.guid_two FROM {$dbprefix}entity_relationships f WHERE f.guid_one = {$guid} AND f.relationship = 'friend')", "mog.guid_one = e.guid", "e.guid != {$guid}"), 'group_by' => 'e.guid', 'order_by' => 'priority desc, ue.last_action desc', 'limit' => 3);
// get members of groups
$mog = elgg_get_entities($options);
foreach ($mog as $m) {
if (!isset($suggestions[$m->guid])) {
$priority = (int) $m->getVolatileData('select:priority');
$suggestions[$m->guid] = array('entity' => $m, 'mutuals' => 0, 'groups' => $priority, 'priority' => $priority);
} else {
$priority = (int) $m->getVolatileData('select:priority');
$suggestions[$m->guid]['groups'] = $priority;
$suggestions[$m->guid]['priority'] += $priority;
}
}
}
// sort by priority
usort($suggestions, __NAMESPACE__ . '\\suggested_friends_sorter');
return $suggestions;
}
开发者ID:epsylon,项目名称:Hydra-dev,代码行数:42,代码来源:functions.php
示例20: generate_query_string
/**
* Generates, encodes, re-orders variables for the query string.
*
* @param array $params The specific parameters for this payment
* @param array $pairs Pairs
* @param string $namespace The namespace
*
* @return string An encoded string of parameters
*/
public static function generate_query_string($params, &$pairs = array(), $namespace = null)
{
if (is_array($params)) {
foreach ($params as $k => $v) {
if (is_int($k)) {
GoCardless_Utils::generate_query_string($v, $pairs, $namespace . '[]');
} else {
GoCardless_Utils::generate_query_string($v, $pairs, $namespace !== null ? $namespace . "[{$k}]" : $k);
}
}
if ($namespace !== null) {
return $pairs;
}
if (empty($pairs)) {
return '';
}
usort($pairs, array(__CLASS__, 'sortPairs'));
$strs = array();
foreach ($pairs as $pair) {
$strs[] = $pair[0] . '=' . $pair[1];
}
return implode('&', $strs);
} else {
$pairs[] = array(rawurlencode($namespace), rawurlencode($params));
}
}
开发者ID:siparker,项目名称:gocardless-whmcs,代码行数:35,代码来源:Utils.php
注:本文中的usort函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论