本文整理汇总了PHP中ksort函数的典型用法代码示例。如果您正苦于以下问题:PHP ksort函数的具体用法?PHP ksort怎么用?PHP ksort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ksort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws InvalidArgumentException
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->detectMagento($output, true);
if (!$this->initMagento()) {
return;
}
$type = $input->getArgument('type');
$areas = array('global', 'adminhtml', 'frontend', 'crontab');
if ($type === null) {
$type = $this->askForArrayEntry($areas, $output, 'Please select an area:');
}
if (!in_array($type, $areas)) {
throw new InvalidArgumentException('Invalid type! Use one of: ' . implode(', ', $areas));
}
if ($input->getOption('format') === null) {
$this->writeSection($output, 'Observers: ' . $type);
}
$frontendEvents = \Mage::getConfig()->getNode($type . '/events')->asArray();
if (true === $input->getOption('sort')) {
// sorting for Observers is a bad idea because the order in which observers will be called is important.
ksort($frontendEvents);
}
$table = array();
foreach ($frontendEvents as $eventName => $eventData) {
$observerList = array();
foreach ($eventData['observers'] as $observer) {
$observerList[] = $this->getObserver($observer, $type);
}
$table[] = array($eventName, implode("\n", $observerList));
}
$this->getHelper('table')->setHeaders(array('Event', 'Observers'))->setRows($table)->renderByFormat($output, $table, $input->getOption('format'));
}
示例2: getSignVeryfy
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @return 签名验证结果
*/
protected function getSignVeryfy($param, $sign)
{
//除去待签名参数数组中的空值和签名参数
$param_filter = array();
while (list($key, $val) = each($param)) {
if ($key == "sign" || $key == "sign_type" || $val == "") {
continue;
} else {
$param_filter[$key] = $param[$key];
}
}
ksort($param_filter);
reset($param_filter);
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = "";
while (list($key, $val) = each($param_filter)) {
$prestr .= $key . "=" . $val . "&";
}
//去掉最后一个&字符
$prestr = substr($prestr, 0, -1);
$prestr = $prestr . $this->config['key'];
$mysgin = md5($prestr);
if ($mysgin == $sign) {
return true;
} else {
return false;
}
}
示例3: parseXmlFiles
public static function parseXmlFiles($templateBaseDir = null)
{
// Read the template folder to find templates
if (!$templateBaseDir) {
$templateBaseDir = KPATH_SITE . '/template';
}
$data = self::parseXmlFile('', $templateBaseDir);
if ($data) {
// Guess template folder.
$data->directory = preg_replace('/[^a-z0-9_]/', '', preg_replace('/\\s+/', '_', strtolower($data->name)));
if (!$data->directory) {
return array();
}
// Template found from the root (folder cannot contain more than one template)
return array('' => $data);
}
$templateDirs = KunenaFolder::folders($templateBaseDir);
$rows = array();
// Check that the directory contains an xml file
foreach ($templateDirs as $templateDir) {
$data = self::parseXmlFile($templateDir, $templateBaseDir);
if ($data) {
$rows[$templateDir] = $data;
}
}
ksort($rows);
return $rows;
}
示例4: apply_filters_ref_array
function apply_filters_ref_array($tag, $args)
{
global $wp_filter, $merged_filters, $wp_current_filter;
// Do 'all' actions first
if (isset($wp_filter['all'])) {
$wp_current_filter[] = $tag;
$all_args = func_get_args();
_wp_call_all_hook($all_args);
}
if (!isset($wp_filter[$tag])) {
if (isset($wp_filter['all'])) {
array_pop($wp_current_filter);
}
return $args[0];
}
if (!isset($wp_filter['all'])) {
$wp_current_filter[] = $tag;
}
// Sort
if (!isset($merged_filters[$tag])) {
ksort($wp_filter[$tag]);
$merged_filters[$tag] = true;
}
reset($wp_filter[$tag]);
do {
foreach ((array) current($wp_filter[$tag]) as $the_) {
if (!is_null($the_['function'])) {
$args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
}
}
} while (next($wp_filter[$tag]) !== false);
array_pop($wp_current_filter);
return $args[0];
}
示例5: PMA_getAvailableMIMEtypes
/**
* Gets all available MIME-types
*
* @return array array[mimetype], array[transformation]
*
* @access public
*
* @author Garvin Hicking <me@supergarv.de>
*/
function PMA_getAvailableMIMEtypes()
{
$handle = opendir('./libraries/transformations');
$stack = array();
$filestack = array();
while (($file = readdir($handle)) != false) {
$filestack[$file] = $file;
}
closedir($handle);
if (is_array($filestack)) {
@ksort($filestack);
foreach ($filestack as $key => $file) {
if (preg_match('|^.*__.*\\.inc\\.php$|', trim($file))) {
// File contains transformation functions.
$base = explode('__', str_replace('.inc.php', '', $file));
$mimetype = str_replace('_', '/', $base[0]);
$stack['mimetype'][$mimetype] = $mimetype;
$stack['transformation'][] = $mimetype . ': ' . $base[1];
$stack['transformation_file'][] = $file;
} elseif (preg_match('|^.*\\.inc\\.php$|', trim($file))) {
// File is a plain mimetype, no functions.
$base = str_replace('.inc.php', '', $file);
if ($base != 'global') {
$mimetype = str_replace('_', '/', $base);
$stack['mimetype'][$mimetype] = $mimetype;
$stack['empty_mimetype'][$mimetype] = $mimetype;
}
}
}
}
return $stack;
}
示例6: _renderCellTemplate
protected function _renderCellTemplate($columnName)
{
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
if ($columnName == "template") {
$collection = Mage::getResourceModel('core/email_template_collection')->load();
$arr_select = $collection->toOptionArray();
array_unshift($arr_select, array('label' => Mage::helper('rewardpoints')->__('Default'), 'value' => ''));
return $this->_getTemplateRenderer()->setName($inputName)->setTitle($columnName)->setExtraParams('style="width:260px"')->setOptions($arr_select)->toHtml();
} else {
if ($columnName == "sender") {
$arr_select = array();
$config = Mage::getSingleton('adminhtml/config')->getSection('trans_email')->groups->children();
foreach ($config as $node) {
$nodeName = $node->getName();
$label = (string) $node->label;
$sortOrder = (int) $node->sort_order;
$arr_select[$sortOrder] = array('value' => preg_replace('#^ident_(.*)$#', '$1', $nodeName), 'label' => Mage::helper('adminhtml')->__($label));
}
ksort($arr_select);
/*array_unshift(
$arr_select,
array(
'label' => Mage::helper('rewardpoints')->__('Default'),
'value' => ''
)
);*/
return $this->_getSenderRenderer()->setName($inputName)->setTitle($columnName)->setExtraParams('style="width:260px"')->setOptions($arr_select)->toHtml();
}
}
return parent::_renderCellTemplate($columnName);
}
示例7: __addPreferences
/**
* Add site preferences
*/
public function __addPreferences($context)
{
// Get selected languages
$selection = Symphony::Configuration()->get('datetime');
if (empty($selection)) {
$selection = array();
}
// Build default options
$options = array();
foreach ($this->languages as $name => $codes) {
$options[$name] = array($name . '::' . $codes, array_key_exists($name, $selection) ? true : false, __(ucfirst($name)));
}
// Add custom options
foreach (array_diff_key($selection, $this->languages) as $name => $codes) {
$options[$name] = array($name . '::' . $codes, true, __(ucfirst($name)));
}
// Sort options
ksort($options);
// Add fieldset
$group = new XMLElement('fieldset', '<legend>' . __('Date and Time') . '</legend>', array('class' => 'settings'));
$select = Widget::Select('settings[datetime][]', $options, array('multiple' => 'multiple'));
$label = Widget::Label('Languages included in the Date and Time Data Source', $select);
$group->appendChild($label);
$help = new XMLElement('p', __('You can add more languages in you configuration file.'), array('class' => 'help'));
$group->appendChild($help);
$context['wrapper']->appendChild($group);
}
示例8: generateSignature
/**
* Add the S3 Authorization signature to the request headers
*
* @param string $method
* @param string $path
* @param array &$headers
* @return string
*/
public function generateSignature($method, $path, &$headers)
{
if (!is_array($headers)) {
$headers = array($headers);
}
$type = $md5 = $date = '';
// Search for the Content-type, Content-MD5 and Date headers
foreach ($headers as $key => $val) {
if (strcasecmp($key, 'content-type') == 0) {
$type = $val;
} else {
if (strcasecmp($key, 'content-md5') == 0) {
$md5 = $val;
} else {
if (strcasecmp($key, 'date') == 0) {
$date = $val;
}
}
}
}
// If we have an x-amz-date header, use that instead of the normal Date
if (isset($headers['x-amz-date']) && isset($date)) {
$date = '';
}
$sig_str = "{$method}\n{$md5}\n{$type}\n{$date}\n";
// For x-amz- headers, combine like keys, lowercase them, sort them
// alphabetically and remove excess spaces around values
$amz_headers = array();
foreach ($headers as $key => $val) {
$key = strtolower($key);
if (substr($key, 0, 6) == 'x-amz-') {
if (is_array($val)) {
$amz_headers[$key] = $val;
} else {
$amz_headers[$key][] = preg_replace('/\\s+/', ' ', $val);
}
}
}
if (!empty($amz_headers)) {
ksort($amz_headers);
foreach ($amz_headers as $key => $val) {
$sig_str .= $key . ':' . implode(',', $val) . "\n";
}
}
$sig_str .= '/' . parse_url($path, PHP_URL_PATH);
if (strpos($path, '?location') !== false) {
$sig_str .= '?location';
} else {
if (strpos($path, '?acl') !== false) {
$sig_str .= '?acl';
} else {
if (strpos($path, '?torrent') !== false) {
$sig_str .= '?torrent';
}
}
}
$signature = base64_encode(Crypt\Hmac::compute($this->_secretKey, 'sha1', utf8_encode($sig_str), Crypt\Hmac::BINARY));
$headers['Authorization'] = 'AWS ' . $this->_accessKey . ':' . $signature;
return $sig_str;
}
示例9: _saveTabs
/**
* Save tab preference order
*
* @return @e void
*/
protected function _saveTabs()
{
//-----------------------------------------
// Store order
//-----------------------------------------
$order = array();
$append = array();
foreach ($this->tabKeys as $pos => $key) {
if ($this->request['pos_' . $key]) {
$order[$this->request['pos_' . $key]] = $key;
} else {
$append[] = $key;
}
}
if (count($append)) {
$order = array_merge($order, $append);
}
ksort($order);
//-----------------------------------------
// Save preference
//-----------------------------------------
ipsRegistry::getClass('adminFunctions')->staffSaveCookie('tabOrder', $order);
//-----------------------------------------
// Return new order
//-----------------------------------------
$this->returnJsonArray(array('order' => $order));
}
示例10: buildContent
/**
* Build the content for this action
*
* @return boolean
* @access public
* @since 4/26/05
*/
function buildContent()
{
$actionRows = $this->getActionRows();
$harmoni = Harmoni::instance();
ob_start();
CollectionsPrinter::printFunctionLinks();
$layout = new Block(ob_get_contents(), STANDARD_BLOCK);
ob_end_clean();
$actionRows->add($layout, null, null, CENTER, CENTER);
$type = HarmoniType::fromString(urldecode(RequestContext::value('type')));
$repositoryManager = Services::getService("Repository");
// Get the Repositories
$allRepositories = $repositoryManager->getRepositoriesByType($type);
// put the repositories into an array and order them.
// @todo, do authorization checking
$repositoryArray = array();
while ($allRepositories->hasNext()) {
$repository = $allRepositories->next();
$repositoryArray[$repository->getDisplayName()] = $repository;
}
ksort($repositoryArray);
// print the Results
$resultPrinter = new ArrayResultPrinter($repositoryArray, 2, 20, "printrepositoryShort", $harmoni);
$resultPrinter->addLinksStyleProperty(new MarginTopSP("10px"));
$resultLayout = $resultPrinter->getLayout();
$actionRows->add($resultLayout, null, null, CENTER, CENTER);
}
示例11: smarty_block_gettext
/**
* Zikula_View function to use the _dgettext() function
*
* This function takes a identifier and returns the corresponding language constant.
*
* Available parameters:
* - text: (required) string to translate
* - tagN: (optional) replace for sprintf() e.g. %s or %1$s
* - domain: (optional) textdomain to be used (not required, the system will fill this out automatically
* - comment: (optional) comment to the translator (this is not processed by this code)
* - assign: If set, the results are assigned to the corresponding variable instead of printed out
*
* Examples
* {gettext}Hello world{/gettext}
* {gettext tag1=$name}Hello %s{/gettext}
* {gettext tag1=$city tag2=$country comment="%1 is a name %2 is the place"}Hello %1$s, welcome to %2$s{/gettext}
*
* String replacement follows the rules at http://php.net/sprintf but please note Smarty seems to pass
* all variables as strings so %s and %n$s are mostly used.
*
* @param array $params All attributes passed to this function from the template.
* @param string $content The block content.
* @param Zikula_View $view Reference to the Zikula_View object.
*
* @return string Translation if it was available.
*/
function smarty_block_gettext($params, $content, Zikula_View $view)
{
if ($content) {
if (isset($params['domain'])) {
$domain = strtolower($params['domain']) == 'zikula' ? null : $params['domain'];
} else {
$domain = $view->getDomain();
// default domain
}
// build array for tags (for %s, %1$s etc) if applicable
ksort($params);
$tags = array();
foreach ($params as $key => $value) {
if (preg_match('#^tag([0-9]{1,2})$#', $key)) {
$tags[] = $value;
}
}
$tags = count($tags) == 0 ? null : $tags;
// perform gettext
$output = isset($tags) ? __f($content, $tags, $domain) : __($content, $domain);
if (isset($params['assign'])) {
$render->assign($params['assign'], $output);
} else {
return $output;
}
}
}
示例12: getLowestPrice
/**
* Returns the price item with the lowest price for the given quantity.
*
* @param array $priceItems List of price items implementing \Aimeos\MShop\Price\Item\Iface
* @param integer $quantity Number of products
* @param string|null $currencyId Three letter ISO currency code or null for all
* @throws \Aimeos\MShop\Price\Exception if no price item is available
*/
public function getLowestPrice(array $priceItems, $quantity, $currencyId = null)
{
$priceList = array();
foreach ($priceItems as $priceItem) {
$iface = '\\Aimeos\\MShop\\Price\\Item\\Iface';
if ($priceItem instanceof $iface === false) {
throw new \Aimeos\MShop\Price\Exception(sprintf('Object is not of required type "%1$s"', $iface));
}
if ($currencyId !== null && $currencyId !== $priceItem->getCurrencyId()) {
continue;
}
$priceList[$priceItem->getQuantity()] = $priceItem;
}
ksort($priceList);
if (($price = reset($priceList)) === false) {
throw new \Aimeos\MShop\Price\Exception(sprintf('Price item not available'));
}
if ($price->getQuantity() > $quantity) {
$msg = sprintf('Price for the given quantity "%1$d" not available', $quantity);
throw new \Aimeos\MShop\Price\Exception($msg);
}
foreach ($priceList as $qty => $priceItem) {
if ($qty <= $quantity && $qty > $price->getQuantity()) {
$price = $priceItem;
}
}
return $price;
}
示例13: _remakeURI
private function _remakeURI($baseurl, $params)
{
// Timestamp パラメータを追加します
// - 時間の表記は ISO8601 形式、タイムゾーンは UTC(GMT)
$params['Timestamp'] = gmdate('Y-m-d\\TH:i:s\\Z');
// パラメータの順序を昇順に並び替えます
ksort($params);
// canonical string を作成します
$canonical_string = '';
foreach ($params as $k => $v) {
$canonical_string .= '&' . $this->_urlencode_rfc3986($k) . '=' . $this->_urlencode_rfc3986($v);
}
$canonical_string = substr($canonical_string, 1);
// 署名を作成します
// - 規定の文字列フォーマットを作成
// - HMAC-SHA256 を計算
// - BASE64 エンコード
$parsed_url = parse_url($baseurl);
$string_to_sign = "GET\n{$parsed_url['host']}\n{$parsed_url['path']}\n{$canonical_string}";
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, SECRET_KEY, true));
// URL を作成します
// - リクエストの末尾に署名を追加
$url = $baseurl . '?' . $canonical_string . '&Signature=' . $this->_urlencode_rfc3986($signature);
return $url;
}
示例14: _run
/**
* Tries to match one of the URL routes to the current URL, otherwise
* execute the default function.
* Sets the callback that needs to be returned
*
* @param string $request
*/
private static function _run($request)
{
// Whether or not we have matched the URL to a route
$matched_route = false;
$request = '/' . $request;
//make sure the request has a trailing slash
$request = rtrim($request, '/') . '/';
$request = str_replace("//", "/", $request);
// Sort the array by priority
ksort(self::$_routes);
// Loop through each priority level
foreach (self::$_routes as $priority => $routes) {
// Loop through each route for this priority level
foreach ($routes as $source => $destination) {
// Does the routing rule match the current URL?
if (preg_match($source, $request, $matches)) {
// A routing rule was matched
$matched_route = TRUE;
$attr = implode('/', array_intersect_key($matches, array_flip(array_filter(array_keys($matches), 'is_string'))));
self::$_attr = explode('/', trim($attr, '/'));
self::_set_callback($destination);
}
}
}
if (!$matched_route) {
if ($request != '/') {
self::_set_callback($request);
}
}
}
示例15: render
/**
* @inheritdoc
*/
public function render($context, $targetDir)
{
parent::render($context, $targetDir);
if ($this->controller !== null) {
$this->controller->stdout("writing packages file...");
}
$packages = [];
$notNamespaced = [];
foreach (array_merge($context->classes, $context->interfaces, $context->traits) as $type) {
/* @var $type TypeDoc */
if (empty($type->namespace)) {
$notNamespaced[] = str_replace('\\', '-', $type->name);
} else {
$packages[$type->namespace][] = str_replace('\\', '-', $type->name);
}
}
ksort($packages);
$packages = array_merge(['Not namespaced' => $notNamespaced], $packages);
foreach ($packages as $name => $classes) {
sort($packages[$name]);
}
file_put_contents($targetDir . '/packages.txt', serialize($packages));
if ($this->controller !== null) {
$this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
}
}