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


PHP array_fill_keys函数代码示例

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


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

示例1: constructFromArray

 /**
  * accepts the object in the form of an array structure
  * @param  [winged] $scale [description]
  * @return [winged]        [description]
  */
 public static function constructFromArray($props)
 {
     $defaults = array_fill_keys(self::$properties, null);
     $props = array_merge($defaults, $props);
     extract($props);
     return new Clef($sign, $line);
 }
开发者ID:ianring,项目名称:phpmusicxml,代码行数:12,代码来源:Clef.php

示例2: format

 /**
  * Injects default parameters before forwarding to the inner formatter.
  *
  * @param string $locale
  * @param string $message
  * @param array(string=>mixed) $parameters
  * @return string The formatted message.
  */
 public function format($locale, $message, array $parameters)
 {
     $variables = (new MessageAnalyzer($message))->getParameters();
     $defaults = array_fill_keys($variables, null);
     $parameters = $parameters + $defaults;
     return parent::format($locale, $message, $parameters);
 }
开发者ID:webfactory,项目名称:icu-translation-bundle,代码行数:15,代码来源:DefaultParameterDecorator.php

示例3: indexAction

 /**
  * @Request({"path"})
  */
 public function indexAction($path)
 {
     if (!($dir = $this->getPath())) {
         return $this->error(__('Invalid path.'));
     }
     if (!is_dir($dir) || '-' === ($mode = $this->getMode($dir))) {
         throw new ForbiddenException(__('Permission denied.'));
     }
     $data = array_fill_keys(['items'], []);
     $data['mode'] = $mode;
     $finder = App::finder();
     $finder->sort(function ($a, $b) {
         return $b->getRealpath() > $a->getRealpath() ? -1 : 1;
     });
     foreach ($finder->depth(0)->in($dir) as $file) {
         if ('-' === ($mode = $this->getMode($file->getPathname()))) {
             continue;
         }
         $info = ['name' => $file->getFilename(), 'mime' => 'application/' . ($file->isDir() ? 'folder' : 'file'), 'path' => $this->normalizePath($path . '/' . $file->getFilename()), 'url' => ltrim(App::url()->getStatic($file->getPathname(), [], 'base'), '/'), 'writable' => $mode == 'w'];
         if (!$file->isDir()) {
             $info = array_merge($info, ['size' => $this->formatFileSize($file->getSize()), 'lastmodified' => date(\DateTime::ISO8601, $file->getMTime())]);
         }
         $data['items'][] = $info;
     }
     return $data;
 }
开发者ID:4nxiety,项目名称:pagekit,代码行数:29,代码来源:FinderController.php

示例4: rs_get_post_revisions

function rs_get_post_revisions($post_id, $status = 'inherit', $args = array())
{
    global $wpdb;
    $defaults = array('order' => 'DESC', 'orderby' => 'post_modified_gmt', 'use_memcache' => true, 'fields' => COLS_ALL_RS, 'return_flipped' => false, 'where' => '');
    $args = wp_parse_args($args, $defaults);
    extract($args);
    if (COL_ID_RS == $fields) {
        // performance opt for repeated calls by user_has_cap filter
        if ($use_memcache) {
            static $last_results;
            if (!isset($last_results)) {
                $last_results = array();
            } elseif (isset($last_results[$post_id][$status])) {
                return $last_results[$post_id][$status];
            }
        }
        $revisions = scoper_get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_parent = '{$post_id}' AND post_status = '{$status}' {$where}");
        if ($return_flipped) {
            $revisions = array_fill_keys($revisions, true);
        }
        if ($use_memcache) {
            if (!isset($last_results[$post_id])) {
                $last_results[$post_id] = array();
            }
            $last_results[$post_id][$status] = $revisions;
        }
    } else {
        $order_clause = $order && $orderby ? "ORDER BY {$orderby} {$order}" : '';
        $revisions = scoper_get_results("SELECT * FROM {$wpdb->posts} WHERE post_type = 'revision' AND post_parent = '{$post_id}' AND post_status = '{$status}' {$order_clause}");
    }
    return $revisions;
}
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:32,代码来源:revisions_lib_rs.php

示例5: prepareFprime

 /**
  * Compute the denominators which is the predicted expectation of
  * each feature given a set of weights L and a set of features for
  * each document for each class.
  * 
  * @param $feature_array All the data known about the training set
  * @param $l The current set of weights to be initialized
  * @return void
  */
 protected function prepareFprime(array &$feature_array, array &$l)
 {
     $this->denominators = array();
     foreach ($feature_array as $offset => $doc) {
         $numerator = array_fill_keys(array_keys($doc), 0.0);
         $denominator = 0.0;
         foreach ($doc as $cl => $f) {
             if (!is_array($f)) {
                 continue;
             }
             $tmp = 0.0;
             foreach ($f as $i) {
                 $tmp += $l[$i];
             }
             $tmp = exp($tmp);
             $numerator[$cl] += $tmp;
             $denominator += $tmp;
         }
         foreach ($doc as $class => $features) {
             if (!is_array($features)) {
                 continue;
             }
             foreach ($features as $fi) {
                 if (!isset($this->denominators[$fi])) {
                     $this->denominators[$fi] = 0;
                 }
                 $this->denominators[$fi] += $numerator[$class] / $denominator;
             }
         }
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:40,代码来源:maxent_grad_descent.php

示例6: update_group_user

 public static function update_group_user($group_id, $user_ids, $args = array())
 {
     $defaults = array('agent_type' => 'pp_group');
     $args = array_merge($defaults, $args);
     extract($args, EXTR_SKIP);
     // NOTE: no arg defaults because we only update columns that are explicitly passed
     if (!($cols = array_intersect_key($args, array_fill_keys(array('status', 'date_limited', 'start_date_gmt', 'end_date_gmt'), true)))) {
         return;
     }
     global $wpdb;
     $members_table = apply_filters('pp_use_group_members_table', $wpdb->pp_group_members, $agent_type);
     $user_clause = "AND user_id IN ('" . implode("', '", array_map('intval', (array) $user_ids)) . "')";
     if (isset($cols['date_limited'])) {
         $cols['date_limited'] = (int) $cols['date_limited'];
     }
     if (isset($cols['start_date_gmt'])) {
         $cols['start_date_gmt'] = self::_validate_duration_value($cols['start_date_gmt']);
     }
     if (isset($cols['end_date_gmt'])) {
         $cols['end_date_gmt'] = self::_validate_duration_value($cols['end_date_gmt']);
     }
     $prev = array();
     $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$members_table} WHERE group_id = %d {$user_clause}", $group_id));
     foreach ($results as $row) {
         $prev[$row->user_id] = $row;
     }
     foreach ((array) $user_ids as $user_id) {
         $wpdb->update($members_table, $cols, array('group_id' => $group_id, 'user_id' => $user_id));
         $_prev = isset($prev[$user_id]) ? $prev[$user_id] : '';
         do_action('pp_update_group_user', $group_id, $user_id, $status, compact('date_limited', 'start_date_gmt', 'end_date_gmt'), $_prev);
     }
 }
开发者ID:severnrescue,项目名称:web,代码行数:32,代码来源:groups-update_pp.php

示例7: addRow

 /**
  * Adds a row to the table with optional values.
  *
  * @param array $values
  */
 public function addRow($values = array())
 {
     $this->data[] = array_merge(
       array_fill_keys($this->getTableMetaData()->getColumns(), NULL),
       $values
     );
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:12,代码来源:DefaultTable.php

示例8: compile

 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     $arrFaq = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         $arrTemp = $objFaq->row();
         $arrTemp['title'] = specialchars($objFaq->question, true);
         $arrTemp['href'] = $this->generateFaqLink($objFaq);
         // Get the FAQ category
         $objPid = $objFaq->getRelated('pid');
         $arrFaq[$objFaq->pid]['items'][] = $arrTemp;
         $arrFaq[$objFaq->pid]['headline'] = $objPid->headline;
         $arrFaq[$objFaq->pid]['title'] = $objPid->title;
     }
     $arrFaq = array_values(array_filter($arrFaq));
     $cat_count = 0;
     $cat_limit = count($arrFaq);
     // Add classes
     foreach ($arrFaq as $k => $v) {
         $count = 0;
         $limit = count($v['items']);
         for ($i = 0; $i < $limit; $i++) {
             $arrFaq[$k]['items'][$i]['class'] = trim((++$count == 1 ? ' first' : '') . ($count >= $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'));
         }
         $arrFaq[$k]['class'] = trim((++$cat_count == 1 ? ' first' : '') . ($cat_count >= $cat_limit ? ' last' : '') . ($cat_count % 2 == 0 ? ' odd' : ' even'));
     }
     $this->Template->faq = $arrFaq;
 }
开发者ID:iCodr8,项目名称:core,代码行数:36,代码来源:ModuleFaqList.php

示例9: extractSenderPhone

 private function extractSenderPhone(&$data, $sender)
 {
     $keys = array_fill_keys(['senderPhone'], null);
     $keySender = array_intersect_key($data['sender']['phone'], $keys);
     $data['senderPhone'] = array_key_exists('senderPhone', $keySender) ? $sender->getPhone()->getSenderPhone() : null;
     return $this;
 }
开发者ID:joelbanzatto,项目名称:laravel-pagseguro,代码行数:7,代码来源:DataRequestHydrator.php

示例10: renderBreadcrumbs

 public function renderBreadcrumbs($slug)
 {
     $ancestor_handles = array();
     $ancestral_slugs = PhabricatorSlug::getAncestry($slug);
     $ancestral_slugs[] = $slug;
     if ($ancestral_slugs) {
         $empty_slugs = array_fill_keys($ancestral_slugs, null);
         $ancestors = id(new PhrictionDocumentQuery())->setViewer($this->getRequest()->getUser())->withSlugs($ancestral_slugs)->execute();
         $ancestors = mpull($ancestors, null, 'getSlug');
         $ancestor_phids = mpull($ancestors, 'getPHID');
         $handles = array();
         if ($ancestor_phids) {
             $handles = $this->loadViewerHandles($ancestor_phids);
         }
         $ancestor_handles = array();
         foreach ($ancestral_slugs as $slug) {
             if (isset($ancestors[$slug])) {
                 $ancestor_handles[] = $handles[$ancestors[$slug]->getPHID()];
             } else {
                 $handle = new PhabricatorObjectHandle();
                 $handle->setName(PhabricatorSlug::getDefaultTitle($slug));
                 $handle->setURI(PhrictionDocument::getSlugURI($slug));
                 $ancestor_handles[] = $handle;
             }
         }
     }
     $breadcrumbs = array();
     foreach ($ancestor_handles as $ancestor_handle) {
         $breadcrumbs[] = id(new PHUICrumbView())->setName($ancestor_handle->getName())->setHref($ancestor_handle->getUri());
     }
     return $breadcrumbs;
 }
开发者ID:pugong,项目名称:phabricator,代码行数:32,代码来源:PhrictionController.php

示例11: __construct

 public function __construct()
 {
     $this->tokenMap = $this->createTokenMap();
     // map of tokens to drop while lexing (the map is only used for isset lookup,
     // that's why the value is simply set to 1; the value is never actually used.)
     $this->dropTokens = array_fill_keys(array(T_WHITESPACE, T_OPEN_TAG), 1);
 }
开发者ID:speak2me,项目名称:pecker,代码行数:7,代码来源:Lexer.php

示例12: getData

 public final function getData($slides, $startIndex, $group)
 {
     $data = array();
     $linearData = $this->_getData($slides * $group, $startIndex - 1);
     $keys = array();
     for ($i = 0; $i < count($linearData); $i++) {
         $keys = array_merge($keys, array_keys($linearData[$i]));
     }
     $columns = array_fill_keys($keys, '');
     for ($i = 0; $i < count($linearData); $i++) {
         $firstIndex = intval($i / $group);
         if (!isset($data[$firstIndex])) {
             $data[$firstIndex] = array();
         }
         $data[$firstIndex][$i % $group] = array_merge($columns, $linearData[$i]);
     }
     if (count($data) && count($data[count($data) - 1]) != $group) {
         if (count($data) - 1 == 0 && count($data[count($data) - 1]) > 0) {
             for ($i = 0; count($data[0]) < $group; $i++) {
                 $data[0][] = $data[0][$i];
             }
         } else {
             array_pop($data);
         }
     }
     return $data;
 }
开发者ID:MBerguer,项目名称:wp-demo,代码行数:27,代码来源:abstract.php

示例13: replacements

 /**
  *
  */
 protected function replacements(array $patterns, $entry, array $options = null)
 {
     $field = $this->_field;
     $fieldname = $field->name;
     $edit = !empty($options['edit']);
     $replacements = array_fill_keys(array_keys($patterns), '');
     if ($edit) {
         foreach ($patterns as $pattern => $cleanpattern) {
             if ($noedit = $this->is_noedit($pattern)) {
                 continue;
             }
             $params = array('required' => $this->is_required($pattern));
             $replacements[$pattern] = array(array($this, 'display_edit'), array($entry, $params));
         }
         return $replacements;
     }
     // Browse mode.
     foreach ($patterns as $pattern => $cleanpattern) {
         $parts = explode(':', trim($cleanpattern, '[]'));
         if (!empty($parts[1])) {
             $type = $parts[1];
         } else {
             $type = '';
         }
         $replacements[$pattern] = $this->display_browse($entry, $type);
     }
     return $replacements;
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:31,代码来源:renderer.php

示例14: replacements

 /**
  *
  */
 protected function replacements(array $patterns, $entry, array $options = null)
 {
     $field = $this->_field;
     $fieldname = $field->name;
     $edit = !empty($options['edit']);
     $replacements = array_fill_keys(array_keys($patterns), '');
     $editdisplayed = false;
     foreach ($patterns as $pattern => $cleanpattern) {
         // Edit.
         if ($edit and !$editdisplayed and !$this->is_noedit($pattern)) {
             $params = array('required' => $this->is_required($pattern));
             if ($cleanpattern == "[[{$fieldname}:addnew]]") {
                 $params['addnew'] = true;
             }
             $replacements[$pattern] = array(array($this, 'display_edit'), array($entry, $params));
             $editdisplayed = true;
             continue;
         }
         // Browse.
         if ($cleanpattern == "[[{$fieldname}:options]]") {
             $replacements[$pattern] = $this->display_browse($entry, array('options' => true));
         } else {
             if ($cleanpattern == "[[{$fieldname}:key]]") {
                 $replacements[$pattern] = $this->display_browse($entry, array('key' => true));
             } else {
                 if ($cleanpattern == "[[{$fieldname}:cat]]") {
                     $replacements[$pattern] = $this->display_category($entry);
                 } else {
                     $replacements[$pattern] = $this->display_browse($entry);
                 }
             }
         }
     }
     return $replacements;
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:38,代码来源:renderer.php

示例15: componentWhiteboardTransitionSelector

 public function componentWhiteboardTransitionSelector()
 {
     foreach ($this->board->getColumns() as $column) {
         if ($column->hasIssue($this->issue)) {
             $this->current_column = $column;
             break;
         }
     }
     $transition_ids = array();
     $same_transition_statuses = array();
     foreach ($this->transitions as $status_id => $transitions) {
         if (!in_array($status_id, $this->statuses)) {
             continue;
         }
         foreach ($transitions as $transition) {
             if (in_array($transition->getID(), $transition_ids)) {
                 $same_transition_statuses[] = $status_id;
             } else {
                 $transition_ids[] = $transition->getID();
             }
         }
     }
     $this->same_transition_statuses = $same_transition_statuses;
     $this->statuses_occurred = array_fill_keys($this->statuses, 0);
 }
开发者ID:founderio,项目名称:thebuggenie,代码行数:25,代码来源:Components.php


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