本文整理汇总了PHP中array_reverse函数的典型用法代码示例。如果您正苦于以下问题:PHP array_reverse函数的具体用法?PHP array_reverse怎么用?PHP array_reverse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_reverse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onls
function onls()
{
$logdir = UC_ROOT . 'data/logs/';
$dir = opendir($logdir);
$logs = $loglist = array();
while ($entry = readdir($dir)) {
if (is_file($logdir . $entry) && strpos($entry, '.php') !== FALSE) {
$logs = array_merge($logs, file($logdir . $entry));
}
}
closedir($dir);
$logs = array_reverse($logs);
foreach ($logs as $k => $v) {
if (count($v = explode("\t", $v)) > 1) {
$v[3] = $this->date($v[3]);
$v[4] = $this->lang[$v[4]];
$loglist[$k] = $v;
}
}
$page = max(1, intval($_GET['page']));
$start = ($page - 1) * UC_PPP;
$num = count($loglist);
$multipage = $this->page($num, UC_PPP, $page, 'admin.php?m=log&a=ls');
$loglist = array_slice($loglist, $start, UC_PPP);
$this->view->assign('loglist', $loglist);
$this->view->assign('multipage', $multipage);
$this->view->display('admin_log');
}
示例2: truncate
/**
* Truncates a string to the given length. It will optionally preserve
* HTML tags if $is_html is set to true.
*
* @param string $string the string to truncate
* @param int $limit the number of characters to truncate too
* @param string $continuation the string to use to denote it was truncated
* @param bool $is_html whether the string has HTML
* @return string the truncated string
*/
public static function truncate($string, $limit, $continuation = '...', $is_html = false)
{
$offset = 0;
$tags = array();
if ($is_html) {
// Handle special characters.
preg_match_all('/&[a-z]+;/i', strip_tags($string), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach ($matches as $match) {
if ($match[0][1] >= $limit) {
break;
}
$limit += static::length($match[0][0]) - 1;
}
// Handle all the html tags.
preg_match_all('/<[^>]+>([^<]*)/', $string, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
foreach ($matches as $match) {
if ($match[0][1] - $offset >= $limit) {
break;
}
$tag = static::sub(strtok($match[0][0], " \t\n\r\v>"), 1);
if ($tag[0] != '/') {
$tags[] = $tag;
} elseif (end($tags) == static::sub($tag, 1)) {
array_pop($tags);
}
$offset += $match[1][1] - $match[0][1];
}
}
$new_string = static::sub($string, 0, $limit = min(static::length($string), $limit + $offset));
$new_string .= static::length($string) > $limit ? $continuation : '';
$new_string .= count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '';
return $new_string;
}
示例3: getPath
public function getPath($categoryId, $accountId, $delimiter = ' > ')
{
$account = Mage::helper('M2ePro/Component_Ebay')->getCachedObject('Account', $accountId);
$categories = $account->getChildObject()->getEbayStoreCategories();
$pathData = array();
while (true) {
$currentCategory = NULL;
foreach ($categories as $category) {
if ($category['category_id'] == $categoryId) {
$currentCategory = $category;
break;
}
}
if (is_null($currentCategory)) {
break;
}
$pathData[] = $currentCategory['title'];
if ($currentCategory['parent_id'] == 0) {
break;
}
$categoryId = $currentCategory['parent_id'];
}
array_reverse($pathData);
return implode($delimiter, $pathData);
}
示例4: create
/** Creates directory or throws exception on fail
* @param string $pathname
* @param int $mode Mode in octal
* @return bool
*/
public static function create($pathname, $mode = self::MOD_DEFAULT)
{
if (strpos($pathname, '/') !== false) {
$pathname = explode('/', $pathname);
}
if (is_array($pathname)) {
$current_dir = '';
$create = array();
do {
$current_dir = implode('/', $pathname);
if (is_dir($current_dir)) {
break;
}
$create[] = array_pop($pathname);
} while (any($pathname));
if (any($create)) {
$create = array_reverse($create);
$current_dir = implode('/', $pathname);
foreach ($create as $dir) {
$current_dir .= '/' . $dir;
if (!is_dir($current_dir)) {
if (!($action = @mkdir($current_dir, $mode))) {
throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $current_dir, base_convert($mode, 10, 8)));
}
}
}
}
} else {
if (!($action = @mkdir($pathname, $mode, true))) {
throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $pathname, base_convert($mode, 10, 8)));
}
}
return $action;
}
示例5: base_getBreadcrumbs
function base_getBreadcrumbs()
{
if (is_404()) {
return false;
}
// Hack to fix breadcrumbs when you're viewing the news home
if (is_home()) {
$post = new \Timber\Post(get_option('page_for_posts'));
} else {
global $post;
}
$breadcrumbs = [];
if ($post->post_parent) {
$parent_id = $post->post_parent;
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = new \Timber\Post($page->ID);
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
}
// Add 'Blog Home' to breadcrumbs if you're on a news post or archive
if ((is_single() || is_archive()) && !is_search()) {
$breadcrumbs[] = new \Timber\Post(get_option('page_for_posts'));
}
return $breadcrumbs;
}
示例6: get_info
public function get_info($base)
{
$sitename = $this->sitename($base);
$c = new Crawler($base);
$c->go_to('id="listing"');
$list = array();
while ($line = $c->readline()) {
if (Crawler::is_there($line, 'class="chico_')) {
if (!Crawler::is_there($line, ' href="')) {
$line = $c->readline();
}
$chp = Crawler::extract($line, 'href="', '"');
$ifx = Crawler::cutfromlast1($chp, '/');
$ifx = str_replace('chapter-', '', $ifx);
$ifx = str_replace('.html', '', $ifx);
$list[] = array('url' => $sitename . $chp, 'infix' => $ifx, 'desc' => strip_tags(Crawler::extract($line, '">', '</td>')));
} else {
if (Crawler::is_there($line, '</table>')) {
break;
}
}
}
$c->close();
return array_reverse($list);
}
示例7: NewStr
public static function NewStr($FinallyStr)
{
if (preg_match('/[^a-z0-9]/i', $FinallyStr)) {
return false;
}
$StrLength = strlen($FinallyStr);
if ($StrLength < 0) {
return false;
}
$NewArr = array();
$i = 0;
$AnStr = str_split($FinallyStr);
$obj = new str_increment();
//instantiation self
do {
$NewAnStr = $obj->Calculation(array_pop($AnStr));
++$i;
$IsDo = false;
if ($NewAnStr !== false) {
if ($NewAnStr === $obj->Table[0]) {
if ($i < $StrLength) {
$IsDo = true;
}
}
$NewArr[] = $NewAnStr;
}
} while ($IsDo);
$ObverseStr = implode('', $AnStr) . implode('', array_reverse($NewArr));
if (self::$FirstRandomCode) {
$ObverseStr = $obj->ReplaceFirstCode($ObverseStr);
}
return $StrLength == strlen($ObverseStr) ? $ObverseStr : false;
}
示例8: testRecreateEntity
public function testRecreateEntity()
{
$type_name = Unicode::strtolower($this->randomMachineName(16));
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
$content_type->save();
node_add_body_field($content_type);
/** @var \Drupal\Core\Config\StorageInterface $active */
$active = $this->container->get('config.storage');
/** @var \Drupal\Core\Config\StorageInterface $sync */
$sync = $this->container->get('config.storage.sync');
$config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
$this->copyConfig($active, $sync);
// Delete the content type. This will also delete a field storage, a field,
// an entity view display and an entity form display.
$content_type->delete();
$this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
// Recreate with the same type - this will have a different UUID.
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
$content_type->save();
node_add_body_field($content_type);
$this->configImporter->reset();
// A node type, a field, an entity view display and an entity form display
// will be recreated.
$creates = $this->configImporter->getUnprocessedConfiguration('create');
$deletes = $this->configImporter->getUnprocessedConfiguration('delete');
$this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
$this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
$this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
$this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
$this->configImporter->import();
// Verify that there is nothing more to import.
$this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
$content_type = NodeType::load($type_name);
$this->assertEqual('Node type one', $content_type->label());
}
示例9: render
/**
* Iterates through elements of $each and renders child nodes
*
* @param array $each The array or SplObjectStorage to iterated over
* @param string $as The name of the iteration variable
* @param string $key The name of the variable to store the current array key
* @param boolean $reverse If enabled, the iterator will start with the last element and proceed reversely
* @return string Rendered string
* @author Sebastian Kurfürst <sebastian@typo3.org>
* @author Bastian Waidelich <bastian@typo3.org>
* @author Robert Lemke <robert@typo3.org>
* @api
*/
public function render($each, $as, $key = '', $reverse = FALSE)
{
$output = '';
if ($each === NULL) {
return '';
}
if (is_object($each)) {
if (!$each instanceof Traversable) {
throw new Tx_Fluid_Core_ViewHelper_Exception('ForViewHelper only supports arrays and objects implementing Traversable interface', 1248728393);
}
$each = $this->convertToArray($each);
}
if ($reverse === TRUE) {
$each = array_reverse($each);
}
$output = '';
foreach ($each as $keyValue => $singleElement) {
$this->templateVariableContainer->add($as, $singleElement);
if ($key !== '') {
$this->templateVariableContainer->add($key, $keyValue);
}
$output .= $this->renderChildren();
$this->templateVariableContainer->remove($as);
if ($key !== '') {
$this->templateVariableContainer->remove($key);
}
}
return $output;
}
示例10: act
function act($qarray)
{
if (isset($_GET['process'])) {
unset($_GET['process']);
unset($qarray['process']);
$_POST['process'] = "true";
}
$args = array_reverse(array_keys($qarray));
$c_name = preg_replace("/[^A-Za-z0-9_]/", "", array_pop($args));
$parts = split("_", $c_name);
$name = "";
foreach ($parts as $p) {
$name .= ucfirst($p);
}
$c_name = $name;
$c_action = preg_replace("/[^A-Za-z0-9_]/", "", array_pop($args));
$args = array_reverse($args);
if (!@call_user_func(array(Controller, "i_once"), $GLOBALS['fileroot'] . "/controllers/C_" . $c_name . ".class.php")) {
echo "Unable to load controller {$name}\n, please check the first argument supplied in the URL and try again";
exit;
}
$obj_name = "C_" . $c_name;
$c_obj = new $obj_name();
if (empty($c_action)) {
$c_action = "default";
}
$c_obj->_current_action = $c_action;
$args_array = array();
foreach ($args as $arg) {
$arg = preg_replace("/[^A-Za-z0-9_]/", "", $arg);
//this is a workaround because call user func does funny things with passing args if they have no assigned value
if (empty($qarray[$arg])) {
//if argument is empty pass null as value and arg as assoc array key
$args_array[$arg] = null;
} else {
$args_array[$arg] = $qarray[$arg];
}
}
$output = "";
//print_r($args_array);
if ($_POST['process'] == "true") {
if (is_callable(array(&$c_obj, $c_action . "_action_process"))) {
//echo "ca: " . $c_action . "_action_process";
$output .= call_user_func_array(array(&$c_obj, $c_action . "_action_process"), $args_array);
if ($c_obj->_state == false) {
return $output;
}
}
//echo "ca: " . $c_action . "_action";
$output .= call_user_func_array(array(&$c_obj, $c_action . "_action"), $args_array);
} else {
if (is_callable(array(&$c_obj, $c_action . "_action"))) {
//echo "ca: " . $c_action . "_action";
$output .= call_user_func_array(array(&$c_obj, $c_action . "_action"), $args_array);
} else {
echo "The action trying to be performed: " . $c_action . " does not exist controller: " . $name;
}
}
return $output;
}
示例11: getHTML
public function getHTML()
{
wfProfileIn(__METHOD__);
$this->report->loadSources();
$aData = array();
$aLabel = array();
if (count($this->report->reportSources) == 0) {
return '';
}
foreach ($this->report->reportSources as $reportSource) {
$reportSource->getData();
$this->actualDate = $reportSource->actualDate;
if (!empty($reportSource->dataAll) && !empty($reportSource->dataTitles)) {
if (is_array($reportSource->dataAll)) {
foreach ($reportSource->dataAll as $key => $val) {
if (isset($aData[$key])) {
$aData[$key] = array_merge($aData[$key], $val);
} else {
$aData[$key] = $val;
}
}
}
$aLabel += $reportSource->dataTitles;
}
}
sort($aData);
$this->sourceData = array_reverse($aData);
$this->sourceLabels = array_reverse($aLabel);
$oTmpl = F::build('EasyTemplate', array(dirname(__FILE__) . "/templates/"));
/** @var $oTmpl EasyTemplate */
$oTmpl->set_vars(array('data' => $this->sourceData, 'labels' => $this->sourceLabels));
wfProfileOut(__METHOD__);
$this->beforePrint();
return $oTmpl->render('../../templates/output/' . self::TEMPLATE_MAIN);
}
示例12: getCommitOrder
/**
* Gets a valid commit order for all current nodes.
*
* Uses a depth-first search (DFS) to traverse the graph.
* The desired topological sorting is the reverse postorder of these searches.
*
* @return array The list of ordered classes.
*/
public function getCommitOrder()
{
// Check whether we need to do anything. 0 or 1 node is easy.
$nodeCount = count($this->_classes);
if ($nodeCount == 0) {
return array();
} else {
if ($nodeCount == 1) {
return array_values($this->_classes);
}
}
// Init
foreach ($this->_classes as $node) {
$this->_nodeStates[$node->name] = self::NOT_VISITED;
}
// Go
foreach ($this->_classes as $node) {
if ($this->_nodeStates[$node->name] == self::NOT_VISITED) {
$this->_visitNode($node);
}
}
$sorted = array_reverse($this->_sorted);
$this->_sorted = $this->_nodeStates = array();
return $sorted;
}
示例13: 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]);
}
示例14: buildExceptionOutput
/**
* Creates the exception output.
*
* @return string the exception output.
*
* @author Tobias Lückel[Megger]
* @version
* Version 0.1, 25.11.2013<br />
*/
protected function buildExceptionOutput()
{
$output = PHP_EOL;
$output .= '[' . $this->generateExceptionID() . ']';
$output .= '[' . $this->exceptionNumber . ']';
$output .= ' ' . $this->exceptionMessage . PHP_EOL;
$output .= self::TAB . $this->exceptionFile . ':' . $this->exceptionLine . PHP_EOL;
$output .= 'Stacktrace:' . PHP_EOL;
$stacktrace = array_reverse($this->exceptionTrace);
foreach ($stacktrace as $item) {
$output .= self::TAB;
if (isset($item['class'])) {
$output .= $item['class'];
}
if (isset($item['type'])) {
$output .= $item['type'];
}
if (isset($item['function'])) {
$output .= $item['function'] . '()';
}
$output .= PHP_EOL;
$output .= self::TAB . self::TAB;
if (isset($item['file'])) {
$output .= $item['file'];
}
if (isset($item['file'])) {
$output .= ':' . $item['line'];
}
$output .= PHP_EOL;
}
$output .= PHP_EOL;
return $output;
}
示例15: setItemstoSend
private function setItemstoSend()
{
foreach ($this->_order->getAllItems() as $item) {
$mcitem = array();
$product = Mage::getSingleton('catalog/product')->load($item->getProductId());
if (in_array($product->getTypeId(), $this->_productsToSkip) && $product->getPriceType() == 0) {
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
$this->_auxPrice = $item->getPrice();
}
continue;
}
$mcitem['product_id'] = $product->getEntityId();
$mcitem['product_name'] = $product->getName();
$names = array();
$cat_ids = $product->getCategoryIds();
if (is_array($cat_ids) && count($cat_ids) > 0) {
$category = Mage::getModel('catalog/category')->load($cat_ids[0]);
$mcitem['category_id'] = $cat_ids[0];
$names[] = $category->getName();
while ($category->getParentId() && $category->getParentId() != 1) {
$category = Mage::getModel('catalog/category')->load($category->getParentId());
$names[] = $category->getName();
}
}
$mcitem['category_name'] = count($names) ? implode(" - ", array_reverse($names)) : 'None';
$mcitem['qty'] = $item->getQtyOrdered();
$mcitem['cost'] = $this->_auxPrice > 0 ? $this->_auxPrice : $item->getPrice();
$this->_info['items'][] = $mcitem;
$this->_auxPrice = 0;
}
return $this;
}