本文整理汇总了PHP中usort函数的典型用法代码示例。如果您正苦于以下问题:PHP usort函数的具体用法?PHP usort怎么用?PHP usort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了usort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例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();
}
示例4: registerLocator
/**
* @param ResourceLocatorInterface $locator
*/
public function registerLocator(ResourceLocatorInterface $locator)
{
$this->locators[] = $locator;
@usort($this->locators, function ($locator1, $locator2) {
return $locator2->getPriority() - $locator1->getPriority();
});
}
示例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]);
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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();
});
}
示例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;
}
示例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);
}
示例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();
}
}
}
示例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;
}
示例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();
});
}