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


PHP array_map函数代码示例

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


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

示例1: nv_getAllowed

/**
 * nv_getAllowed()
 *
 * @return
 */
function nv_getAllowed()
{
    global $module_data, $db, $admin_info;
    $sql = 'SELECT id,full_name,admins FROM ' . NV_PREFIXLANG . '_' . $module_data . '_department';
    $result = $db->query($sql);
    $contact_allowed = array('view' => array(), 'reply' => array(), 'obt' => array());
    while ($row = $result->fetch()) {
        $id = intval($row['id']);
        if (defined('NV_IS_SPADMIN')) {
            $contact_allowed['view'][$id] = $row['full_name'];
            $contact_allowed['reply'][$id] = $row['full_name'];
        }
        $admins = $row['admins'];
        $admins = array_map('trim', explode(';', $admins));
        foreach ($admins as $a) {
            if (preg_match('/^([0-9]+)\\/([0-1]{1})\\/([0-1]{1})\\/([0-1]{1})$/i', $a)) {
                $admins2 = array_map('intval', explode('/', $a));
                if ($admins2[0] == $admin_info['admin_id']) {
                    if ($admins2[1] == 1 and !isset($contact_allowed['view'][$id])) {
                        $contact_allowed['view'][$id] = $row['full_name'];
                    }
                    if ($admins2[2] == 1 and !isset($contact_allowed['reply'][$id])) {
                        $contact_allowed['reply'][$id] = $row['full_name'];
                    }
                    if ($admins2[3] == 1 and !isset($contact_allowed['obt'][$id])) {
                        $contact_allowed['obt'][$id] = $row['full_name'];
                    }
                }
            }
        }
    }
    return $contact_allowed;
}
开发者ID:lzhao18,项目名称:nukeviet,代码行数:38,代码来源:admin.functions.php

示例2: setValue

 /**
  * Sets selected items (by keys).
  * @param  array
  * @return self
  */
 public function setValue($values)
 {
     if (is_scalar($values) || $values === NULL) {
         $values = (array) $values;
     } elseif (!is_array($values)) {
         throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
     }
     $flip = [];
     foreach ($values as $value) {
         if (!is_scalar($value) && !method_exists($value, '__toString')) {
             throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
         }
         $flip[(string) $value] = TRUE;
     }
     $values = array_keys($flip);
     if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
         $set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
             return var_export($s, TRUE);
         }, array_keys($this->items))), 70, '...');
         $vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
         throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed set [{$set}] in field '{$this->name}'.");
     }
     $this->value = $values;
     return $this;
 }
开发者ID:jjanekk,项目名称:forms,代码行数:30,代码来源:MultiChoiceControl.php

示例3: farmtoyou_paging_nav

    /**
     * Display navigation to next/previous set of posts when applicable.
     *
     * @since Farmtoyou 1.0
     *
     * @global WP_Query   $wp_query   WordPress Query object.
     * @global WP_Rewrite $wp_rewrite WordPress Rewrite object.
     */
    function farmtoyou_paging_nav()
    {
        global $wp_query, $wp_rewrite;
        // Don't print empty markup if there's only one page.
        if ($wp_query->max_num_pages < 2) {
            return;
        }
        $paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1;
        $pagenum_link = html_entity_decode(get_pagenum_link());
        $query_args = array();
        $url_parts = explode('?', $pagenum_link);
        if (isset($url_parts[1])) {
            wp_parse_str($url_parts[1], $query_args);
        }
        $pagenum_link = remove_query_arg(array_keys($query_args), $pagenum_link);
        $pagenum_link = trailingslashit($pagenum_link) . '%_%';
        $format = $wp_rewrite->using_index_permalinks() && !strpos($pagenum_link, 'index.php') ? 'index.php/' : '';
        $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit($wp_rewrite->pagination_base . '/%#%', 'paged') : '?paged=%#%';
        // Set up paginated links.
        $links = paginate_links(array('base' => $pagenum_link, 'format' => $format, 'total' => $wp_query->max_num_pages, 'current' => $paged, 'mid_size' => 1, 'add_args' => array_map('urlencode', $query_args), 'prev_text' => __('&larr; Previous', 'farmtoyou'), 'next_text' => __('Next &rarr;', 'farmtoyou')));
        if ($links) {
            ?>
	<nav class="navigation paging-navigation" role="navigation">
		<div class="pagination loop-pagination">
			<?php 
            echo $links;
            ?>
		</div><!-- .pagination -->
	</nav><!-- .navigation -->
	<?php 
        }
    }
开发者ID:abcode619,项目名称:wpstuff,代码行数:40,代码来源:template-tags.php

示例4: afterExample

 public function afterExample(ExampleEvent $event)
 {
     $total = $this->stats->getEventsCount();
     $counts = $this->stats->getCountsHash();
     $percents = array_map(function ($count) use($total) {
         return round($count / ($total / 100), 0);
     }, $counts);
     $lengths = array_map(function ($percent) {
         return round($percent / 2, 0);
     }, $percents);
     $size = 50;
     asort($lengths);
     $progress = array();
     foreach ($lengths as $status => $length) {
         $text = $percents[$status] . '%';
         $length = $size - $length >= 0 ? $length : $size;
         $size = $size - $length;
         if ($length > strlen($text) + 2) {
             $text = str_pad($text, $length, ' ', STR_PAD_BOTH);
         } else {
             $text = str_pad('', $length, ' ');
         }
         $progress[$status] = sprintf("<{$status}-bg>%s</{$status}-bg>", $text);
     }
     krsort($progress);
     $this->printException($event, 2);
     $this->io->writeTemp(implode('', $progress) . ' ' . $total);
 }
开发者ID:phpspec,项目名称:phpspec2,代码行数:28,代码来源:ProgressFormatter.php

示例5: checkFileContent

 protected static function checkFileContent()
 {
     $fileContent = file_get_contents(static::$tmpFilepath);
     // check encoding and convert to utf-8 when necessary
     $detectedEncoding = mb_detect_encoding($fileContent, 'UTF-8, ISO-8859-1, WINDOWS-1252', true);
     if ($detectedEncoding) {
         if ($detectedEncoding !== 'UTF-8') {
             $fileContent = iconv($detectedEncoding, 'UTF-8', $fileContent);
         }
     } else {
         echo 'Zeichensatz der CSV-Date stimmt nicht. Der sollte UTF-8 oder ISO-8856-1 sein.';
         return false;
     }
     //prepare data array
     $tmpData = str_getcsv($fileContent, PHP_EOL);
     array_shift($tmpData);
     $preparedData = [];
     $data = array_map(function ($row) use(&$preparedData) {
         $tmpDataArray = str_getcsv($row, ';');
         $tmpKey = trim($tmpDataArray[0]);
         array_shift($tmpDataArray);
         $preparedData[$tmpKey] = $tmpDataArray;
     }, $tmpData);
     // generate json
     $jsonContent = json_encode($preparedData, JSON_HEX_TAG | JSON_HEX_AMP);
     self::$jsonContent = $jsonContent;
     return true;
 }
开发者ID:antic183,项目名称:php-fileupload-encrypt-json,代码行数:28,代码来源:CsvUploader.php

示例6: _parseIndexerString

 /**
  * Parse string with indexers and return array of indexer instances
  *
  * @param string $string
  * @return array
  */
 protected function _parseIndexerString($string)
 {
     $processes = array();
     if ($string == 'all') {
         $collection = $this->_getIndexer()->getProcessesCollection();
         foreach ($collection as $process) {
             if ($process->getIndexer()->isVisible() === false) {
                 continue;
             }
             $processes[] = $process;
         }
     } else {
         if (!empty($string)) {
             $codes = explode(',', $string);
             $codes = array_map('trim', $codes);
             $processes = $this->_getIndexer()->getProcessesCollectionByCodes($codes);
             foreach ($processes as $key => $process) {
                 if ($process->getIndexer()->getVisibility() === false) {
                     unset($processes[$key]);
                 }
             }
             if ($this->_getIndexer()->hasErrors()) {
                 echo implode(PHP_EOL, $this->_getIndexer()->getErrors()), PHP_EOL;
             }
         }
     }
     return $processes;
 }
开发者ID:vishalpatel14,项目名称:indiankalaniketan,代码行数:34,代码来源:indexer.php

示例7: paginate

 function paginate($term = null, $paginateOptions = array())
 {
     $this->_controller->paginate = array('SearchIndex' => array_merge_recursive(array('conditions' => array(array('SearchIndex.active' => 1), 'or' => array(array('SearchIndex.published' => null), array('SearchIndex.published <= ' => date('Y-m-d H:i:s'))))), $paginateOptions));
     if (isset($this->_controller->request->params['named']['type']) && $this->_controller->request->params['named']['type'] != 'All') {
         $this->_controller->request->data['SearchIndex']['type'] = Sanitize::escape($this->_controller->request->params['named']['type']);
         $this->_controller->paginate['SearchIndex']['conditions']['model'] = $this->_controller->data['SearchIndex']['type'];
     }
     // Add term condition, and sorting
     if (!$term && isset($this->_controller->request->params['named']['term'])) {
         $term = $this->_controller->request->params['named']['term'];
     }
     if ($term) {
         $term = Sanitize::escape($term);
         $this->_controller->request->data['SearchIndex']['term'] = $term;
         $term = implode(' ', array_map(array($this, 'replace'), preg_split('/[\\s_]/', $term))) . '*';
         if ($this->like) {
             $this->_controller->paginate['SearchIndex']['conditions'][] = array('or' => array("MATCH(data) AGAINST('{$term}')", 'SearchIndex.data LIKE' => "%{$this->_controller->data['SearchIndex']['term']}%"));
         } else {
             $this->_controller->paginate['SearchIndex']['conditions'][] = "MATCH(data) AGAINST('{$term}' IN BOOLEAN MODE)";
         }
         $this->_controller->paginate['SearchIndex']['fields'] = "*, MATCH(data) AGAINST('{$term}' IN BOOLEAN MODE) AS score";
         if (empty($this->_controller->paginate['SearchIndex']['order'])) {
             $this->_controller->paginate['SearchIndex']['order'] = "score DESC";
         }
     }
     return $this->_controller->paginate('SearchIndex');
 }
开发者ID:josegonzalez,项目名称:searchable,代码行数:27,代码来源:SearchComponent.php

示例8: dd

 /**
  * Dump & Die
  *
  * @codeCoverageIgnore
  */
 function dd()
 {
     array_map(function ($x) {
         var_dump($x);
     }, func_get_args());
     die;
 }
开发者ID:arcanedev,项目名称:arabic,代码行数:12,代码来源:helpers.php

示例9: preSave

 /**
  * Handle pre save event
  *
  * @param LifecycleEventArgs $args Event arguments
  */
 protected function preSave(LifecycleEventArgs $args)
 {
     $annotations = $this->container->get('cyber_app.metadata.reader')->getUploadebleFieldsAnnotations($args->getEntity());
     if (0 === count($annotations)) {
         return;
     }
     foreach ($annotations as $field => $annotation) {
         $config = $this->container->getParameter('oneup_uploader.config.' . $annotation->endpoint);
         if (!(isset($config['use_orphanage']) && $config['use_orphanage'])) {
             continue;
         }
         $value = (array) PropertyAccess::createPropertyAccessor()->getValue($args->getEntity(), $field);
         $value = array_filter($value, 'strlen');
         $value = array_map(function ($file) {
             return pathinfo($file, PATHINFO_BASENAME);
         }, $value);
         if (empty($value)) {
             continue;
         }
         $orphanageStorage = $this->container->get('oneup_uploader.orphanage.' . $annotation->endpoint);
         $files = [];
         foreach ($orphanageStorage->getFiles() as $file) {
             if (in_array($file->getBasename(), $value, true)) {
                 $files[] = $file;
             }
         }
         $orphanageStorage->uploadFiles($files);
     }
 }
开发者ID:snovichkov,项目名称:UploaderBundle,代码行数:34,代码来源:UploadListener.php

示例10: GetNumbersFromList

 private static function GetNumbersFromList($Admins)
 {
     $Function = function ($Admin) {
         return $Admin[0];
     };
     return array_map($Function, $Admins);
 }
开发者ID:RhuanGonzaga,项目名称:WhatsBot,代码行数:7,代码来源:Admin.php

示例11: XMLAppend

 /**
  * Append any supported $content to $parent
  *
  * @param  DOMNode $parent  Node to append to
  * @param  mixed   $content Content to append
  * @return self
  */
 protected function XMLAppend(\DOMNode &$parent = null, $content = null)
 {
     if (is_null($parent)) {
         $parent = $this->root;
     }
     if (is_string($content) or is_numeric($content) or is_object($content) and method_exists($content, '__toString')) {
         $parent->appendChild($this->createTextNode("{$content}"));
     } elseif (is_object($content) and is_subclass_of($content, '\\DOMNode')) {
         $parent->appendChild($content);
     } elseif (is_array($content) or is_object($content) and $content = get_object_vars($content)) {
         array_map(function ($node, $value) use(&$parent) {
             if (is_string($node)) {
                 if (substr($node, 0, 1) === '@') {
                     $parent->setAttribute(substr($node, 1), $value);
                 } else {
                     $node = $parent->appendChild($this->createElement($node));
                     if (is_string($value)) {
                         $this->XMLAppend($node, $this->createTextNode($value));
                     } else {
                         $this->XMLAppend($node, $value);
                     }
                 }
             } else {
                 $this->XMLAppend($parent, $value);
             }
         }, array_keys($content), array_values($content));
     } elseif (is_bool($content)) {
         $parent->appendChild($this->createTextNode($content ? 'true' : 'false'));
     } else {
         throw new \InvalidArgumentException(sprintf('Unable to append unknown content [%s] to %s', get_class($content), get_class($this)));
     }
     return $this;
 }
开发者ID:KVSun,项目名称:core_api,代码行数:40,代码来源:xmlappend.php

示例12: partition

 public function partition(...$partitions)
 {
     $this->partitions = array_merge($this->partitions, array_map(function ($partition) {
         return is_string($partition) ? new SqlLiteral($partition) : $partition;
     }, $partitions));
     return $this;
 }
开发者ID:LartTyler,项目名称:Link,代码行数:7,代码来源:WindowNode.php

示例13: login

 public function login()
 {
     function callback($v)
     {
         if (empty($v)) {
             return $v = '';
         } else {
             return $v;
         }
     }
     $userinfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
     $data = array('store_id' => intval($_GET['store_id']), 'wecha_id' => $this->wecha_id, 'token' => $this->token, 'wechaname' => $userinfo['wechaname'], 'portrait' => $userinfo['portrait'], 'tel' => $userinfo['tel'], 'address' => $userinfo['address'], 'return_url' => '');
     $sort_data = $data;
     $sort_data['salt'] = $this->SALT;
     ksort($sort_data);
     $sort_data = array_map('callback', $sort_data);
     $sign_key = sha1(http_build_query($sort_data));
     $data['sign_key'] = $sign_key;
     $data['request_time'] = time();
     $url = $this->Micrstore_URL . '/api/fans.php';
     $return = json_decode($this->curl_post($url, $data), true);
     $return_data = $sort_data;
     unset($return_data['salt']);
     unset($return_data['return_url']);
     $return_data['sessid'] = $return['sessid'];
     $return_url = $this->_get('return_url') . '&' . http_build_query(array('token' => $data['token'], 'wecha_id' => $data['wecha_id'], 'sessid' => $return['sessid']));
     header('Location: ' . $return_url);
 }
开发者ID:liuguogen,项目名称:weixin,代码行数:28,代码来源:MicrstoreAction.class.php

示例14: fromString

 /**
  * Create a new SetCookie object from a string
  *
  * @param string $cookie Set-Cookie header string
  *
  * @return self
  */
 public static function fromString($cookie)
 {
     // Create the default return array
     $data = self::$defaults;
     // Explode the cookie string using a series of semicolons
     $pieces = array_filter(array_map('trim', explode(';', $cookie)));
     // The name of the cookie (first kvp) must include an equal sign.
     if (empty($pieces) || !strpos($pieces[0], '=')) {
         return new self($data);
     }
     // Add the cookie pieces into the parsed data array
     foreach ($pieces as $part) {
         $cookieParts = explode('=', $part, 2);
         $key = trim($cookieParts[0]);
         $value = isset($cookieParts[1]) ? trim($cookieParts[1], " \n\r\t\v\"") : true;
         // Only check for non-cookies when cookies have been found
         if (empty($data['Name'])) {
             $data['Name'] = $key;
             $data['Value'] = $value;
         } else {
             foreach (array_keys(self::$defaults) as $search) {
                 if (!strcasecmp($search, $key)) {
                     $data[$search] = $value;
                     continue 2;
                 }
             }
             $data[$key] = $value;
         }
     }
     return new self($data);
 }
开发者ID:hexcode007,项目名称:yfcms,代码行数:38,代码来源:SetCookie.php

示例15: sql_connect

 /**
  * Connect to server
  */
 function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
 {
     $this->persistency = $persistency;
     $this->user = $sqluser;
     $this->server = $sqlserver;
     $this->dbname = $database;
     $port = !$port ? NULL : $port;
     // Persistant connections not supported by the mysqli extension?
     $this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port);
     if ($this->db_connect_id && $this->dbname != '') {
         @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'");
         // enforce strict mode on databases that support it
         if (version_compare($this->sql_server_info(true), '5.0.2', '>=')) {
             $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode');
             $row = @mysqli_fetch_assoc($result);
             @mysqli_free_result($result);
             $modes = array_map('trim', explode(',', $row['sql_mode']));
             // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES
             if (!in_array('TRADITIONAL', $modes)) {
                 if (!in_array('STRICT_ALL_TABLES', $modes)) {
                     $modes[] = 'STRICT_ALL_TABLES';
                 }
                 if (!in_array('STRICT_TRANS_TABLES', $modes)) {
                     $modes[] = 'STRICT_TRANS_TABLES';
                 }
             }
             $mode = implode(',', $modes);
             @mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'");
         }
         return $this->db_connect_id;
     }
     return $this->sql_error('');
 }
开发者ID:nodemodular,项目名称:digital-whispers,代码行数:36,代码来源:mysqli.php


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