當前位置: 首頁>>代碼示例>>PHP>>正文


PHP usort函數代碼示例

本文整理匯總了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();
 }
開發者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


注:本文中的usort函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。