本文整理汇总了PHP中sort函数的典型用法代码示例。如果您正苦于以下问题:PHP sort函数的具体用法?PHP sort怎么用?PHP sort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_token_from_guids
function get_token_from_guids($guids)
{
$guids = array_unique($guids);
sort($guids);
$string = implode(',', $guids);
return md5($string);
}
示例2: getArrClasses
/**
*
* get array of slide classes, between two sections.
*/
public function getArrClasses($startText = "", $endText = "", $explodeonspace = false)
{
$content = $this->cssContent;
//trim from top
if (!empty($startText)) {
$posStart = strpos($content, $startText);
if ($posStart !== false) {
$content = substr($content, $posStart, strlen($content) - $posStart);
}
}
//trim from bottom
if (!empty($endText)) {
$posEnd = strpos($content, $endText);
if ($posEnd !== false) {
$content = substr($content, 0, $posEnd);
}
}
//get styles
$lines = explode("\n", $content);
$arrClasses = array();
foreach ($lines as $key => $line) {
$line = trim($line);
if (strpos($line, "{") === false) {
continue;
}
//skip unnessasary links
if (strpos($line, ".caption a") !== false) {
continue;
}
if (strpos($line, ".tp-caption a") !== false) {
continue;
}
//get style out of the line
$class = str_replace("{", "", $line);
$class = trim($class);
//skip captions like this: .tp-caption.imageclass img
if (strpos($class, " ") !== false) {
if (!$explodeonspace) {
continue;
} else {
$class = explode(',', $class);
$class = $class[0];
}
}
//skip captions like this: .tp-caption.imageclass:hover, :before, :after
if (strpos($class, ":") !== false) {
continue;
}
$class = str_replace(".caption.", ".", $class);
$class = str_replace(".tp-caption.", ".", $class);
$class = str_replace(".", "", $class);
$class = trim($class);
$arrWords = explode(" ", $class);
$class = $arrWords[count($arrWords) - 1];
$class = trim($class);
$arrClasses[] = $class;
}
sort($arrClasses);
return $arrClasses;
}
示例3: getFolderList
/**
* Image Manager Popup
*
* @param string $listFolder The image directory to display
* @since 1.5
*/
function getFolderList($base = null)
{
global $mainframe;
// Get some paths from the request
if (empty($base)) {
$base = JA_WORKING_DATA_FOLDER;
}
// Get the list of folders
jimport('joomla.filesystem.folder');
$folders = JFolder::folders($base, '.', 4, true);
// Load appropriate language files
$lang =& JFactory::getLanguage();
$lang->load(JRequest::getCmd('option'), JPATH_ADMINISTRATOR);
$document =& JFactory::getDocument();
$document->setTitle(JText::_('Insert Image'));
// Build the array of select options for the folder list
$options[] = JHTML::_('select.option', "", "/");
foreach ($folders as $folder) {
$folder = str_replace(JA_WORKING_DATA_FOLDER, "", $folder);
$value = substr($folder, 1);
$text = str_replace(DS, "/", $folder);
$options[] = JHTML::_('select.option', $value, $text);
}
// Sort the folder list array
if (is_array($options)) {
sort($options);
}
// Create the drop-down folder select list
$list = JHTML::_('select.genericlist', $options, 'folderlist', "class=\"inputbox\" size=\"1\" onchange=\"ImageManager.setFolder(this.options[this.selectedIndex].value)\" ", 'value', 'text', $base);
return $list;
}
示例4: listCommands
private static function listCommands()
{
$commands = array();
$dir = __DIR__;
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && $entry != "base.php") {
$s1 = explode("cli_", $entry);
$s2 = explode(".php", $s1[1]);
if (sizeof($s2) == 2) {
require_once "{$dir}/{$entry}";
$command = $s2[0];
$className = "cli_{$command}";
$class = new $className();
if (is_a($class, "cliCommand")) {
$commands[] = $command;
}
}
}
}
closedir($handle);
}
sort($commands);
return implode(" ", $commands);
}
示例5: getTableList
/**
* getTableList
*
* @return Array A list of tables based off the table schema that should be present in the system.
*/
public function getTableList()
{
$tables = $this->getExpectedSchema();
$tables = array_keys($tables);
sort($tables);
return $tables;
}
示例6: run
/**
* Execute the action.
*
* @param array command line parameters specific for this command
*/
public function run($args)
{
$runner = $this->getCommandRunner();
$commands = $runner->commands;
if (isset($args[0])) {
$name = strtolower($args[0]);
}
if (!isset($args[0]) || !isset($commands[$name])) {
echo <<<EOD
At the prompt, you may enter a PHP statement or one of the following commands:
EOD;
$commandNames = array_keys($commands);
sort($commandNames);
echo ' - ' . implode("\n - ", $commandNames);
echo <<<EOD
Type 'help <command-name>' for details about a command.
To expand the above command list, place your command class files
under 'protected/commands/shell', or a directory specified
by the 'YIIC_SHELL_COMMAND_PATH' environment variable. The command class
must extend from CConsoleCommand.
EOD;
} else {
echo $runner->createCommand($name)->getHelp();
}
}
示例7: getAvailable
/**
* Gets a pipe-separated string of available languages
*
* @return string
*/
public function getAvailable()
{
$languagesArray = $this->languages;
//Make local copy
sort($languagesArray);
return implode('|', array_reverse($languagesArray));
}
示例8: setup_files
/**
* Takes the included files and breaks up into mutli arrays for use in the debugger
* @param array $files
* @return Ambigous <multitype:unknown , unknown>
*/
public function setup_files(array $files)
{
sort($files);
$path_third = realpath(eedt_third_party_path());
$path_ee = realpath(APPPATH);
$path_first_modules = realpath(PATH_MOD);
$bootstrap_file = FCPATH . SELF;
$return = array();
foreach ($files as $file) {
if (strpos($file, $path_third) === 0) {
$return['third_party_addon'][] = $file;
continue;
}
if (strpos($file, $path_first_modules) === 0) {
$return['first_party_modules'][] = $file;
continue;
}
if (strpos($file, $bootstrap_file) === 0) {
$return['bootstrap_file'] = $file;
continue;
}
if (strpos($file, $path_ee) === 0) {
$return['expressionengine_core'][] = $file;
continue;
}
$return['other_files'][] = $file;
}
return $return;
}
示例9: beforeFilter
public function beforeFilter()
{
parent::beforeFilter();
// Update current semester, if needed
if (date('m') < 5) {
// Winter semester
$this->currentSemester = date('Y') . '01';
} elseif (date('m') < 9) {
// Summer semester
$this->currentSemester = date('Y') . '05';
} else {
// Autumn semester
$this->currentSemester = date('Y') . '09';
}
if ($this->Session->read('Registration.semester') != '') {
$this->registrationSemester = $this->Session->read('Registration.semester');
} else {
$this->registrationSemester = '201501';
$this->Session->write('Registration.semester', $this->registrationSemester);
}
// If unregistration is still possible for current semester, add it to the registration semesters list
if (!in_array($this->currentSemester, $this->registrationSemesters) && $this->deadlines[$this->currentSemester]['drop_fee'] >= date('Ymd')) {
$this->registrationSemesters[] = $this->currentSemester;
sort($this->registrationSemesters);
}
}
示例10: testMode
/**
* @dataProvider dataProviderForMode
*/
public function testMode(array $numbers, $modes)
{
$computed_modes = Average::mode($numbers);
sort($modes);
sort($computed_modes);
$this->assertEquals($modes, $computed_modes);
}
示例11: display_array_content_style
function display_array_content_style($arrayname, $method, $base_url)
{
$a = "";
sort($arrayname);
while (list($key, $value) = each($arrayname)) {
if (is_array($value)) {
$c = display_array_content($value, '');
$d = ltrim($c, "0");
$d = str_replace("-", "", $c);
$a .= "<a id='modal_window_link' href='" . $base_url . "output/print.output.php?section=styles&view=" . $c . "&tb=true'>" . $d . "</a>";
} else {
$e = ltrim($value, "0");
$e = str_replace("-", "", $value);
$a .= "<a id='modal_window_link' href='" . $base_url . "output/print.output.php?section=styles&view=" . $value . "&tb=true'>" . $e . "</a>";
}
if ($method == "1") {
$a .= "";
}
if ($method == "2") {
$a .= " ";
}
if ($method == "3") {
$a .= ", ";
}
}
$b = rtrim($a, " ");
$b = rtrim($b, " ");
return $b;
}
示例12: execute
public function execute(PhutilArgumentParser $args)
{
$can_recover = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withIsAdmin(true)->execute();
if (!$can_recover) {
throw new PhutilArgumentUsageException(pht('This Phabricator installation has no recoverable administrator ' . 'accounts. You can use `bin/accountadmin` to create a new ' . 'administrator account or make an existing user an administrator.'));
}
$can_recover = mpull($can_recover, 'getUsername');
sort($can_recover);
$can_recover = implode(', ', $can_recover);
$usernames = $args->getArg('username');
if (!$usernames) {
throw new PhutilArgumentUsageException(pht('You must specify the username of the account to recover.'));
} else {
if (count($usernames) > 1) {
throw new PhutilArgumentUsageException(pht('You can only recover the username for one account.'));
}
}
$username = head($usernames);
$user = id(new PhabricatorPeopleQuery())->setViewer($this->getViewer())->withUsernames(array($username))->executeOne();
if (!$user) {
throw new PhutilArgumentUsageException(pht('No such user "%s". Recoverable administrator accounts are: %s.', $username, $can_recover));
}
if (!$user->getIsAdmin()) {
throw new PhutilArgumentUsageException(pht('You can only recover administrator accounts, but %s is not an ' . 'administrator. Recoverable administrator accounts are: %s.', $username, $can_recover));
}
$engine = new PhabricatorAuthSessionEngine();
$onetime_uri = $engine->getOneTimeLoginURI($user, null, PhabricatorAuthSessionEngine::ONETIME_RECOVER);
$console = PhutilConsole::getConsole();
$console->writeOut(pht('Use this link to recover access to the "%s" account from the web ' . 'interface:', $username));
$console->writeOut("\n\n");
$console->writeOut(' %s', $onetime_uri);
$console->writeOut("\n\n");
$console->writeOut(pht('After logging in, you can use the "Auth" application to add or ' . 'restore authentication providers and allow normal logins to ' . 'succeed.') . "\n");
return 0;
}
示例13: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Ensure that the signable query string parameters are sorted
sort($this->signableQueryString);
// Add the security token header if one is being used by the credentials
if ($token = $credentials->getSecurityToken()) {
$request->setHeader('x-amz-security-token', $token);
}
$request->removeHeader('x-amz-date');
$request->setHeader('Date', gmdate(\DateTime::RFC2822));
$stringToSign = $this->createCanonicalizedString($request);
$request->getParams()->set('aws.string_to_sign', $stringToSign);
$request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
// COMMONLOG(DEBUG, "send header:%s",$request->getRawHeaders());
// if(self::$isFile)
// {
// if(self::$filePath)
// COMMONLOG(DEBUG, "souce file:%s",self::$filePath);
// }
// else
// {
// if(get_class($request) === 'Guzzle\Http\Message\EntityEnclosingRequest' && get_class($request->getBody()) === 'Guzzle\Http\EntityBody' && $request->getBody()->getContentLength() != 0)
// {
// COMMONLOG(DEBUG, "send msg:%s",$request->getBody());
// }
// }
}
示例14: get_data
private function get_data()
{
$this->ci->db->join('rm r', 'r.mid = m.mid');
$this->ci->db->join('url u', 'u.rid = r.rid');
$query = $this->ci->db->get_where('mn m', ['u.uid' => $this->id, 'm.mstat' => TRUE]);
$result = $query->result_array();
if (!empty($result)) {
$data = [];
$tmp = [];
foreach ($result as $val) {
$mpar = $val['mpar'] == 1 ? 0 : $val['mpar'];
$tmp[$val['mid']][] = json_decode_db($val['rmk']);
$data[$val['mid']] = ['mid' => $val['mid'], 'mpar' => $mpar, 'mnme' => $val['mnme'], 'mico' => $val['mico'], 'mlnk' => $val['mlnk']];
}
$array_key = [];
foreach ($tmp as $k => $v) {
$array_key[$k] = [];
foreach ($v as $vv) {
if (is_array($vv) == FALSE) {
continue;
}
$array_key[$k] = array_merge($array_key[$k], $vv);
}
$array_key[$k] = array_unique($array_key[$k]);
sort($array_key[$k]);
}
foreach ($data as $kk => $vvv) {
$data[$kk]['key'] = $array_key[$kk];
}
}
return isset($data) ? $data : [];
}
示例15: test_nonunique_postmeta
function test_nonunique_postmeta()
{
// Add two non unique post meta item
$this->assertInternalType('integer', add_post_meta($this->post_id, 'nonunique', 'value'));
$this->assertInternalType('integer', add_post_meta($this->post_id, 'nonunique', 'another value'));
//Check they exists
$this->assertEquals('value', get_post_meta($this->post_id, 'nonunique', true));
$this->assertEquals(array('value', 'another value'), get_post_meta($this->post_id, 'nonunique', false));
//Fail to delete the wrong value
$this->assertFalse(delete_post_meta($this->post_id, 'nonunique', 'wrong value'));
//Delete the first one
$this->assertTrue(delete_post_meta($this->post_id, 'nonunique', 'value'));
//Check the remainder exists
$this->assertEquals('another value', get_post_meta($this->post_id, 'nonunique', true));
$this->assertEquals(array('another value'), get_post_meta($this->post_id, 'nonunique', false));
//Add a third one
$this->assertInternalType('integer', add_post_meta($this->post_id, 'nonunique', 'someother value'));
//Check they exists
$expected = array('someother value', 'another value');
sort($expected);
$this->assertTrue(in_array(get_post_meta($this->post_id, 'nonunique', true), $expected));
$actual = get_post_meta($this->post_id, 'nonunique', false);
sort($actual);
$this->assertEquals($expected, $actual);
//Delete the lot
$this->assertTrue(delete_post_meta_by_key('nonunique'));
}