当前位置: 首页>>代码示例>>PHP>>正文


PHP strnatcmp函数代码示例

本文整理汇总了PHP中strnatcmp函数的典型用法代码示例。如果您正苦于以下问题:PHP strnatcmp函数的具体用法?PHP strnatcmp怎么用?PHP strnatcmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了strnatcmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: user_function_sort

 function user_function_sort($arr)
 {
     usort($arr, function ($a, $b) {
         return strnatcmp($a['value'], $b['value']);
     });
     return $arr;
 }
开发者ID:NaszvadiG,项目名称:ImageCMS,代码行数:7,代码来源:array_helper.php

示例2: sort

 public function sort(ProxySourceItem $a, ProxySourceItem $b)
 {
     if ($a->date() && $a->title() && $b->date() && $b->title()) {
         return strnatcmp($b->date() . ' ' . $b->title(), $a->date() . ' ' . $a->title());
     }
     return strnatcmp($a->relativePathname(), $b->relativePathname());
 }
开发者ID:georgjaehnig,项目名称:sculpin,代码行数:7,代码来源:DefaultSorter.php

示例3: _c_sort

function _c_sort($a, $b)
{
    global $ary;
    $a_re = false;
    $b_re = false;
    $i = 0;
    foreach ($ary as $nanme => $regexp) {
        if ($a_re !== false && $b_re !== false) {
            break;
        }
        if ($a_re === false && preg_match($regexp, $a)) {
            $a_re = $i;
        }
        if ($b_re === false && preg_match($regexp, $b)) {
            $b_re = $i;
        }
        $i++;
    }
    if ($a_re < $b_re) {
        return -1;
    } elseif ($a_re > $b_re) {
        return 1;
    } else {
        return strnatcmp($a, $b);
    }
}
开发者ID:h16o2u9u,项目名称:rtoss,代码行数:26,代码来源:index.php

示例4: sortOpponents

 public function sortOpponents($key, $order)
 {
     // sort teams by column name in $key, order is either 'asc' or 'desc'
     return function ($a, $b) use($key, $order) {
         return $order === 'desc' ? strnatcmp($b->{$key}, $a->{$key}) : strnatcmp($a->{$key}, $b->{$key});
     };
 }
开发者ID:laiello,项目名称:bz-owl,代码行数:7,代码来源:teamOpponents.php

示例5: get

 public function get()
 {
     /** @var \Tacit\Model\Persistent $modelClass */
     $modelClass = static::$modelClass;
     $criteria = $this->criteria(func_get_args());
     $limit = $this->app->request->get('limit', 25);
     $offset = $this->app->request->get('offset', 0);
     $orderBy = $this->app->request->get('sort', $modelClass::key());
     $orderDir = $this->app->request->get('sort_dir', 'desc');
     try {
         $total = $modelClass::count($criteria, $this->app->container->get('repository'));
         $collection = $modelClass::find($criteria, [], $this->app->container->get('repository'));
         if ($collection === null) {
             $collection = [];
         }
         if ($collection && $orderBy) {
             usort($collection, function ($a, $b) use($orderBy, $orderDir) {
                 switch ($orderDir) {
                     case 'desc':
                     case 'DESC':
                     case -1:
                         return strnatcmp($b->{$orderBy}, $a->{$orderBy});
                     default:
                         return strnatcmp($a->{$orderBy}, $b->{$orderBy});
                 }
             });
         }
         if ($collection && $limit > 0) {
             $collection = array_slice($collection, $offset, $limit);
         }
     } catch (\Exception $e) {
         throw new ServerErrorException($this, 'Error retrieving collection', $e->getMessage(), null, $e);
     }
     $this->respondWithCollection($collection, $this->transformer(), ['total' => $total]);
 }
开发者ID:vgrish,项目名称:tacit,代码行数:35,代码来源:MockRestfulCollection.php

示例6: index

 public function index($tab = '', $page = '')
 {
     $modules = $objects = array();
     foreach ($this->addons->get_modules(TRUE) as $module) {
         foreach ($module->get_access() as $type => $access) {
             if (!empty($access['get_all']) && ($get_all = call_user_func($access['get_all']))) {
                 $modules[$module->name] = array($module, $module->icon, $type, $access);
                 $objects[$module->name] = $get_all;
             }
         }
     }
     uasort($modules, function ($a, $b) {
         return strnatcmp($a[0]->get_title(), $b[0]->get_title());
     });
     foreach ($modules as $module_name => $module) {
         if ($tab === '' || $module_name == $tab) {
             $objects = $objects[$module_name];
             foreach ($objects as &$object) {
                 list($id, $title) = array_values($object);
                 $object = array('id' => $id, 'title' => $module[0]->load->lang($title, NULL));
                 unset($object);
             }
             $tab = $module_name;
             break;
         }
     }
     return array($this->load->library('pagination')->get_data($objects, $page), $modules, $tab);
 }
开发者ID:agreements,项目名称:neofrag-cms,代码行数:28,代码来源:admin_checker.php

示例7: php_min_ver

/**
 * PHP version check
 *
 * @param $ver minimum version number
 * @return true if we are running at least PHP $ver
 */
function php_min_ver($ver)
{
    if (strnatcmp(phpversion(), $ver) < 0) {
        return false;
    }
    return true;
}
开发者ID:martinlindhe,项目名称:core_dev,代码行数:13,代码来源:core.php

示例8: subscriptions_compare_by_name

function subscriptions_compare_by_name($a, $b)
{
    $an = $a['name'];
    $bn = $b['name'];
    $result = strnatcmp($an, $bn);
    return $result;
}
开发者ID:hypeJunction,项目名称:Elgg-user_settings,代码行数:7,代码来源:collections.php

示例9: actionProcess

 public function actionProcess($num, FactorizationService $factorizationService, Connection $redis, Response $response)
 {
     $factors = $errorMsg = '';
     if (PHP_INT_SIZE === 4) {
         $maxInt = "2147483647";
     } else {
         $maxInt = "9223372036854775807";
     }
     try {
         if (preg_match('#\\D#', $num)) {
             throw new Exception('В числе должны быть только цифры.');
         }
         if (0 < strnatcmp((string) $num, (string) $maxInt)) {
             throw new Exception('Слишком большое число.');
         }
         if ($factors = $redis->hget(self::HASH_KEY, $num)) {
             $factors = unserialize($factors);
         } else {
             $factors = $factorizationService->trialDivision((int) $num);
             if ($redis->hlen(self::HASH_KEY) == self::MAX_HASH_LEN) {
                 $redis->del(self::HASH_KEY);
             }
             $redis->hset(self::HASH_KEY, $num, serialize($factors));
         }
     } catch (Exception $e) {
         $errorMsg = $e->getMessage();
     }
     $response->format = Response::FORMAT_JSON;
     return ['data' => $factors, 'error' => $errorMsg];
 }
开发者ID:LIME-,项目名称:yii2-test-task,代码行数:30,代码来源:FactorizationController.php

示例10: compare

 /**
  * Performs a comparison between two values and returns an integer result, like strnatcmp.
  *
  * @param string $value1
  * @param string $value2
  * @return int
  */
 public static function compare($value1, $value2)
 {
     if (self::isIntlLoaded()) {
         return self::getCollator()->compare($value1, $value2);
     }
     return strnatcmp($value1, $value2);
 }
开发者ID:ldaptools,项目名称:ldaptools,代码行数:14,代码来源:MBString.php

示例11: append

 /**
  * Scan the directory at the given path and include
  * all files. Only 1 level iteration.
  *
  * @param string $path The directory/file path.
  * @return bool True. False if not appended.
  */
 protected function append($path)
 {
     $files = [];
     if (is_dir($path)) {
         $dir = new \DirectoryIterator($path);
         foreach ($dir as $file) {
             if (!$file->isDot() || !$file->isDir()) {
                 $file_extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
                 if ($file_extension === 'php') {
                     $this->names[] = $file->getBasename('.php');
                     $files[] = ['name' => $file->getBasename('.php'), 'path' => $file->getPath() . DS . $file->getBasename()];
                 }
             }
         }
         // Organize files per alphabetical order
         // and include them.
         if (!empty($files)) {
             usort($files, function ($a, $b) {
                 return strnatcmp($a['name'], $b['name']);
             });
             foreach ($files as $file) {
                 include_once $file['path'];
             }
         }
         return true;
     }
     return false;
 }
开发者ID:mwerezi,项目名称:framework,代码行数:35,代码来源:Loader.php

示例12: index

 function index()
 {
     /**
      * If the PHP version is greater than 5.3.0 it
      * will support Anonymous functions
      */
     if (strnatcmp(phpversion(), '5.3.0') >= 0) {
         add_action('before_title', function () {
             echo '<small>This text is prepended before the title</small>';
         });
         add_action('after_title', function () {
             echo '<small>This text is appended after the title</small> <hr/>';
         });
     }
     /**
      * Add some class specific actions
      */
     add_action('before_content', array($this, 'action_before_content'));
     add_action('after_content', array($this, 'action_after_content'));
     /**
      * Add filters to the content (1 global function and 1 class specific function)
      */
     add_filter('content', 'replace_ipsum', 30);
     //global function (see above) with 30 priority
     add_filter('content', array($this, 'filter_add_author_to_content'), 10);
     //class function (see below) with 10 priority (first executed)
     /**
      *  add time to the title and underline the word title
      */
     add_filter('title', array($this, 'filter_add_time_to_the_title'));
     //add a time to the title
     $data = array('content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi at sem leo. Pellentesque sed ipsum tortor sed mi gravida imperdiet ac sed magna. Nunc tempor libero nec ligula ullamcorper euismod. Sed adipiscing consectetur metus eget congue. ipsum dignissim mauris nec risus tempus vulputate. Ut in arcu felis. Sed imperdiet mollis ipsum. Aliquam non lacus libero, eu tristique urna. ipsum Morbi vel gravida justo. Curabitur sed velit lorem, nec ultrices odio. Cras et magna vel purus dapibus egestas. Etiam massa eros, pretium eget venenatis fermentum, tincidunt id nisl. Aenean ut felis velit. Donec non neque congue nibh convallis pretium. Nam egestas luctus eros ac elementum. Vestibulum nisl sapien, pellentesque sit amet pulvinar at, ullamcorper in purus.');
     $this->load->view('hooking_example', $data);
 }
开发者ID:NaszvadiG,项目名称:codeigniter-hooking,代码行数:34,代码来源:hooking_example.php

示例13: sort

 public static function sort(&$paths, $method, $direction)
 {
     if (!self::validOrderMethod($method) || !self::validOrderDirection($direction)) {
         throw new Exception('Invalid order params');
     }
     if ($method === 'name') {
         usort($paths, function ($a, $b) {
             return strnatcmp($a->name, $b->name);
         });
     } elseif ($method === 'time') {
         usort($paths, function ($a, $b) {
             if ($a->rawTime === $b->rawTime) {
                 return 0;
             }
             return $a->rawTime > $b->rawTime ? 1 : -1;
         });
     }
     if ($method === 'size') {
         usort($paths, function ($a, $b) {
             if ($a->rawSize === $b->rawSize) {
                 return 0;
             }
             return $a->rawSize > $b->rawSize ? 1 : -1;
         });
     }
     if ($direction === 'desc') {
         $paths = array_reverse($paths);
     }
 }
开发者ID:Lord-Simon,项目名称:MangaIndex,代码行数:29,代码来源:Sorting.php

示例14: getConfigurationArrayFromExtensionKey

 /**
  * Converts the raw configuration file content to an configuration object storage
  *
  * @param string $extensionKey Extension key
  * @return array
  */
 protected function getConfigurationArrayFromExtensionKey($extensionKey)
 {
     /** @var $configurationUtility \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility */
     $configurationUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility::class);
     $defaultConfiguration = $configurationUtility->getDefaultConfigurationFromExtConfTemplateAsValuedArray($extensionKey);
     $resultArray = array();
     if (!empty($defaultConfiguration)) {
         $metaInformation = $this->addMetaInformation($defaultConfiguration);
         $configuration = $this->mergeWithExistingConfiguration($defaultConfiguration, $extensionKey);
         $hierarchicConfiguration = array();
         foreach ($configuration as $configurationOption) {
             $originalConfiguration = $this->buildConfigurationArray($configurationOption, $extensionKey);
             ArrayUtility::mergeRecursiveWithOverrule($originalConfiguration, $hierarchicConfiguration);
             $hierarchicConfiguration = $originalConfiguration;
         }
         // Flip category array as it was merged the other way around
         $hierarchicConfiguration = array_reverse($hierarchicConfiguration);
         // Sort configurations of each subcategory
         foreach ($hierarchicConfiguration as &$catConfigurationArray) {
             foreach ($catConfigurationArray as &$subcatConfigurationArray) {
                 uasort($subcatConfigurationArray, function ($a, $b) {
                     return strnatcmp($a['subcat'], $b['subcat']);
                 });
             }
             unset($subcatConfigurationArray);
         }
         unset($tempConfiguration);
         ArrayUtility::mergeRecursiveWithOverrule($hierarchicConfiguration, $metaInformation);
         $resultArray = $hierarchicConfiguration;
     }
     return $resultArray;
 }
开发者ID:plan2net,项目名称:TYPO3.CMS,代码行数:38,代码来源:ConfigurationItemRepository.php

示例15: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Sync our local folder with the S3 Bucket...');
     $sync = $this->getApplication()->make('operations.s3-sync');
     $sync->sync();
     $output->writeln('Getting the list of files to be processed...');
     $finder = new Finder();
     $finder->files('*.json')->in($this->directories['files_dir'])->sort(function ($a, $b) {
         return strnatcmp($a->getRealPath(), $b->getRealPath());
     });
     if (file_exists($this->directories['last_read_file'])) {
         $lastFile = file_get_contents($this->directories['last_read_file']);
         $finder->filter(function ($file) use($lastFile) {
             if (0 >= strnatcmp($file->getFilename(), $lastFile)) {
                 return false;
             }
             return true;
         });
     }
     $importer = $this->getApplication()->make('operations.file-importer');
     foreach ($finder as $file) {
         $output->writeln('Processing the events from ' . $file->getFilename() . '...');
         $importer->from($file);
         file_put_contents($this->directories['last_read_file'], $file->getFilename());
     }
 }
开发者ID:jlcd,项目名称:kissmetrics-to-database,代码行数:26,代码来源:ProcessFilesCommand.php


注:本文中的strnatcmp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。