本文整理汇总了PHP中ArrayObject::uksort方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayObject::uksort方法的具体用法?PHP ArrayObject::uksort怎么用?PHP ArrayObject::uksort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayObject
的用法示例。
在下文中一共展示了ArrayObject::uksort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Scans and parses PHP files.
*
* @return array
* @throws \RuntimeException If no PHP files have been found.
*/
public function parse()
{
$files = array();
$flags = \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS;
if (defined('\\RecursiveDirectoryIterator::FOLLOW_SYMLINKS')) {
// Available from PHP 5.3.1
$flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
}
foreach ($this->config->source as $source) {
$entries = array();
if (is_dir($source)) {
foreach (new \RecursiveIteratorIterator(new SourceFilesFilterIterator(new \RecursiveDirectoryIterator($source, $flags), $this->config->exclude)) as $entry) {
if (!$entry->isFile()) {
continue;
}
$entries[] = $entry;
}
} elseif ($this->isPhar($source)) {
if (!extension_loaded('phar')) {
throw new RuntimeException('Phar extension is not loaded');
}
foreach (new \RecursiveIteratorIterator(new \Phar($source, $flags)) as $entry) {
if (!$entry->isFile()) {
continue;
}
$entries[] = $entry;
}
} else {
$entries[] = new \SplFileInfo($source);
}
$regexp = '~\\.' . implode('|', $this->config->extensions->toArray()) . '$~i';
foreach ($entries as $entry) {
if (!preg_match($regexp, $entry->getFilename())) {
continue;
}
$pathName = $this->normalizePath($entry->getPathName());
$files[$pathName] = $entry->getSize();
if (false !== $entry->getRealPath() && $pathName !== $entry->getRealPath()) {
$this->symlinks[$entry->getRealPath()] = $pathName;
}
}
}
if (empty($files)) {
throw new RuntimeException('No PHP files found');
}
$this->fireEvent('parseStart', array_sum($files));
$broker = new Broker(new Backend($this, !empty($this->config->report)), Broker::OPTION_DEFAULT & ~(Broker::OPTION_PARSE_FUNCTION_BODY | Broker::OPTION_SAVE_TOKEN_STREAM));
$errors = array();
foreach ($files as $filePath => $size) {
$content = $this->charsetConvertor->convertFile($filePath);
try {
$broker->processString($content, $filePath);
} catch (\Exception $e) {
$errors[] = $e;
}
$this->fireEvent('parseProgress', $size);
}
// Classes
$this->parsedClasses->exchangeArray($broker->getClasses(Backend::TOKENIZED_CLASSES | Backend::INTERNAL_CLASSES | Backend::NONEXISTENT_CLASSES));
$this->parsedClasses->uksort('strcasecmp');
// Constants
$this->parsedConstants->exchangeArray($broker->getConstants());
$this->parsedConstants->uksort('strcasecmp');
// Functions
$this->parsedFunctions->exchangeArray($broker->getFunctions());
$this->parsedFunctions->uksort('strcasecmp');
$documentedCounter = function ($count, $element) {
return $count += (int) $element->isDocumented();
};
return (object) array('classes' => count($broker->getClasses(Backend::TOKENIZED_CLASSES)), 'constants' => count($this->parsedConstants), 'functions' => count($this->parsedFunctions), 'internalClasses' => count($broker->getClasses(Backend::INTERNAL_CLASSES)), 'documentedClasses' => array_reduce($broker->getClasses(Backend::TOKENIZED_CLASSES), $documentedCounter), 'documentedConstants' => array_reduce($this->parsedConstants->getArrayCopy(), $documentedCounter), 'documentedFunctions' => array_reduce($this->parsedFunctions->getArrayCopy(), $documentedCounter), 'documentedInternalClasses' => array_reduce($broker->getClasses(Backend::INTERNAL_CLASSES), $documentedCounter), 'errors' => $errors);
}
示例2: ArrayObject
<?php
/* Prototype : int ArrayObject::uksort(callback cmp_function)
* Description: proto int ArrayIterator::uksort(callback cmp_function)
Sort the entries by key using user defined function.
* Source code: ext/spl/spl_array.c
* Alias to functions:
*/
$ao = new ArrayObject();
try {
$ao->uksort();
} catch (BadMethodCallException $e) {
echo $e->getMessage() . "\n";
}
try {
$ao->uksort(1, 2);
} catch (BadMethodCallException $e) {
echo $e->getMessage() . "\n";
}
?>
===DONE===
示例3: cmp
<?php
function cmp($a, $b)
{
$a = preg_replace('@^(a|an|the) @', '', $a);
$b = preg_replace('@^(a|an|the) @', '', $b);
return strcasecmp($a, $b);
}
$array = array("John" => 1, "the Earth" => 2, "an apple" => 3, "a banana" => 4);
$arrayObject = new ArrayObject($array);
$arrayObject->uksort('cmp');
foreach ($arrayObject as $key => $value) {
echo "{$key}: {$value}\n";
}
示例4: cmp
<?php
/* Prototype : int ArrayObject::uksort(callback cmp_function)
* Description: proto int ArrayIterator::uksort(callback cmp_function)
* Sort the entries by key using user defined function.
* Source code: ext/spl/spl_array.c
* Alias to functions:
*/
echo "*** Testing ArrayObject::uksort() : basic functionality ***\n";
// Reverse sorter
function cmp($value1, $value2)
{
if ($value1 == $value2) {
return 0;
} else {
if ($value1 < $value2) {
return 1;
} else {
return -1;
}
}
}
$ao = new ArrayObject(array(3 => 0, 2 => 1, 5 => 2, 6 => 3, 1 => 4));
$ao->uksort('cmp');
var_dump($ao);
?>
===DONE===
示例5: uksort
public function uksort($cmp_function)
{
$this->lazyLoadArray();
parent::uksort($cmp_function);
}
示例6: uksort
/**
* Implementation of ArrayObject::uksort().
*
* This function sorts the keys of the entries using a user-supplied
* comparison function. The key to entry correlations will be maintained.
*
* No value is returned.
*
* @param callable $cmpFunction The callback comparison function.
*/
public function uksort($cmpFunction)
{
$this->arrayObject->uksort($cmpFunction);
}