本文整理汇总了PHP中array_combine函数的典型用法代码示例。如果您正苦于以下问题:PHP array_combine函数的具体用法?PHP array_combine怎么用?PHP array_combine使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_combine函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderContent
/**
* (non-PHPdoc)
* @see CPortlet::renderContent()
*/
protected function renderContent()
{
$themesList = array_combine(Yii::app()->themeManager->themeNames, Yii::app()->themeManager->themeNames);
echo CHtml::form('', 'post', array());
echo CHtml::dropDownList('themeSelector', Yii::app()->theme->name, $themesList, $this->dropDownOptions);
echo CHtml::endForm();
}
示例2: format
/**
* format a monetary string
*
* Format a monetary string basing on the amount provided,
* ISO currency code provided and a format string consisting of:
*
* %a - the formatted amount
* %C - the currency ISO code (e.g., 'USD') if provided
* %c - the currency symbol (e.g., '$') if available
*
* @param float $amount the monetary amount to display (1234.56)
* @param string $currency the three-letter ISO currency code ('USD')
* @param string $format the desired currency format
*
* @return string formatted monetary string
*
* @static
*/
static function format($amount, $currency = null, $format = null)
{
if (CRM_Utils_System::isNull($amount)) {
return '';
}
$config =& CRM_Core_Config::singleton();
if (!self::$_currencySymbols) {
require_once "CRM/Core/PseudoConstant.php";
$currencySymbolName = CRM_Core_PseudoConstant::currencySymbols('name');
$currencySymbol = CRM_Core_PseudoConstant::currencySymbols();
self::$_currencySymbols = array_combine($currencySymbolName, $currencySymbol);
}
if (!$currency) {
$currency = $config->defaultCurrency;
}
if (!$format) {
$format = $config->moneyformat;
}
// money_format() exists only in certain PHP install (CRM-650)
if (is_numeric($amount) and function_exists('money_format')) {
$amount = money_format($config->moneyvalueformat, $amount);
}
$replacements = array('%a' => $amount, '%C' => $currency, '%c' => CRM_Utils_Array::value($currency, self::$_currencySymbols, $currency));
return strtr($format, $replacements);
}
示例3: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
$type = $this->entity;
if ($this->operation == 'add') {
$form['#title'] = $this->t('Add log type');
$fields = $this->entityManager->getBaseFieldDefinitions('log');
// Create a node with a fake bundle using the type's UUID so that we can
// get the default values for workflow settings.
// @todo Make it possible to get default values without an entity.
// https://www.drupal.org/node/2318187
$node = $this->entityManager->getStorage('log')->create(array('type' => $type->uuid()));
} else {
$form['#title'] = $this->t('Edit %label log type', array('%label' => $type->label()));
$fields = $this->entityManager->getFieldDefinitions('log', $type->id());
// Create a node to get the current values for workflow settings fields.
$node = $this->entityManager->getStorage('log')->create(array('type' => $type->id()));
}
$form['name'] = array('#title' => t('Name'), '#type' => 'textfield', '#default_value' => $type->label(), '#description' => t('The human-readable name of this log type. This text will be displayed as part of the list on the <em>Add content</em> page. This name must be unique.'), '#required' => TRUE, '#size' => 30);
$form['type'] = array('#type' => 'machine_name', '#default_value' => $type->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('exists' => ['Drupal\\node\\Entity\\LogType', 'load'], 'source' => array('name')), '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %log-add page, in which underscores will be converted into hyphens.', array('%log-add' => t('Add content'))));
$form['description'] = array('#title' => t('Description'), '#type' => 'textarea', '#default_value' => $type->getDescription(), '#description' => t('This text will be displayed on the <em>Add new content</em> page.'));
$form['additional_settings'] = array('#type' => 'vertical_tabs', '#attached' => array('library' => array('node/drupal.content_types')));
$form['submission'] = array('#type' => 'details', '#title' => t('Submission form settings'), '#group' => 'additional_settings', '#open' => TRUE);
$form['submission']['preview_mode'] = array('#type' => 'radios', '#title' => t('Preview before submitting'), '#default_value' => $type->getPreviewMode(), '#options' => array(DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), DRUPAL_REQUIRED => t('Required')));
$form['submission']['help'] = array('#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => $type->getHelp(), '#description' => t('This text will be displayed at the top of the page when creating or editing content of this type.'));
$form['workflow'] = array('#type' => 'details', '#title' => t('Publishing options'), '#group' => 'additional_settings');
$workflow_options = array('status' => $node->status->value, 'promote' => $node->promote->value, 'sticky' => $node->sticky->value, 'revision' => $type->isNewRevision());
// Prepare workflow options to be used for 'checkboxes' form element.
$keys = array_keys(array_filter($workflow_options));
$workflow_options = array_combine($keys, $keys);
$form['workflow']['options'] = array('#type' => 'checkboxes', '#title' => t('Default options'), '#default_value' => $workflow_options, '#options' => array('status' => t('Published'), 'promote' => t('Promoted to front page'), 'sticky' => t('Sticky at top of lists'), 'revision' => t('Create new revision')), '#description' => t('Users with the <em>Administer content</em> permission will be able to override these options.'));
$form['display'] = array('#type' => 'details', '#title' => t('Display settings'), '#group' => 'additional_settings');
$form['display']['display_submitted'] = array('#type' => 'checkbox', '#title' => t('Display author and date information'), '#default_value' => $type->displaySubmitted(), '#description' => t('Author username and publish date will be displayed.'));
return $this->protectBundleIdElement($form);
}
示例4: getWidgetOptionsForColumn
public function getWidgetOptionsForColumn($column)
{
$options = array();
$withEmpty = sprintf('\'with_empty\' => %s', $column->isNotNull() ? 'false' : 'true');
switch ($column->getDoctrineType()) {
case 'boolean':
$options[] = "'choices' => array('' => dm::getI18n()->__('yes or no', array(), 'dm'), 1 => dm::getI18n()->__('yes', array(), 'dm'), 0 => dm::getI18n()->__('no', array(), 'dm'))";
break;
case 'date':
case 'datetime':
case 'timestamp':
$widget = 'new sfWidgetFormInputText(array(), array("class" => "datepicker_me"))';
$options[] = "'from_date' => {$widget}, 'to_date' => {$widget}";
$options[] = $withEmpty;
break;
case 'enum':
$values = array('' => '');
$values = array_merge($values, $column['values']);
$values = array_combine($values, $values);
$options[] = "'choices' => " . str_replace("\n", '', $this->arrayExport($values));
break;
}
if ($column->isForeignKey()) {
$options[] = sprintf('\'model\' => \'%s\', \'add_empty\' => true', $column->getForeignTable()->getOption('name'));
}
return count($options) ? sprintf('array(%s)', implode(', ', $options)) : '';
}
示例5: wds_autolinks_settings
function wds_autolinks_settings()
{
$name = 'wds_autolinks';
$title = __('Automatic Links', 'wds');
$description = __('<p>Sometimes you want to always link certain key words to a page on your blog or even a whole new site all together.</p>
<p>For example, maybe anytime you write the words \'WordPress news\' you want to automatically create a link to the WordPress news blog, wpmu.org. Without this plugin, you would have to manually create these links each time you write the text in your pages and posts - which can be no fun at all.</p>
<p>This section lets you set those key words and links. First, choose if you want to automatically link key words in posts, pages, or any custom post types you might be using. Usually when you are using automatic links, you will want to check all of the options here.</p>', 'wds');
$fields = array();
foreach (get_post_types() as $post_type) {
if (!in_array($post_type, array('revision', 'nav_menu_item', 'attachment'))) {
$pt = get_post_type_object($post_type);
$key = strtolower($pt->name);
$post_types["l{$key}"] = $pt->labels->name;
$insert["{$key}"] = $pt->labels->name;
}
}
foreach (get_taxonomies() as $taxonomy) {
if (!in_array($taxonomy, array('nav_menu', 'link_category', 'post_format'))) {
$tax = get_taxonomy($taxonomy);
$key = strtolower($tax->labels->name);
$taxonomies["l{$key}"] = $tax->labels->name;
}
}
$linkto = array_merge($post_types, $taxonomies);
$insert['comment'] = __('Comments', 'wds');
$fields['internal'] = array('title' => '', 'intro' => '', 'options' => array(array('type' => 'checkbox', 'name' => 'insert', 'title' => __('Insert links in', 'wds'), 'items' => $insert), array('type' => 'checkbox', 'name' => 'linkto', 'title' => __('Link to', 'wds'), 'items' => $linkto), array('type' => 'dropdown', 'name' => 'cpt_char_limit', 'title' => __('Minimum post title length', 'wds'), 'description' => __('This is the minimum number of characters your post title has to have to be considered for insertion as auto-link.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 25)), array_merge(array(__('Default', 'wds')), range(1, 25)))), array('type' => 'dropdown', 'name' => 'tax_char_limit', 'title' => __('Minimum taxonomy title length', 'wds'), 'description' => __('This is the minimum number of characters your taxonomy title has to have to be considered for insertion as auto-link.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 25)), array_merge(array(__('Default', 'wds')), range(1, 25)))), array('type' => 'checkbox', 'name' => 'allow_empty_tax', 'title' => __('Empty taxonomies', 'wds'), 'items' => array('allow_empty_tax' => __('Allow autolinks to empty taxonomies', 'wds'))), array('type' => 'checkbox', 'name' => 'excludeheading', 'title' => __('Exclude Headings', 'wds'), 'items' => array('excludeheading' => __('Prevent linking in heading tags', 'wds'))), array('type' => 'text', 'name' => 'ignorepost', 'title' => __('Ignore posts and pages', 'wds'), 'description' => __('Paste in the IDs, slugs or titles for the post/pages you wish to exclude and separate them by commas', 'wds')), array('type' => 'text', 'name' => 'ignore', 'title' => __('Ignore keywords', 'wds'), 'description' => __('Paste in the keywords you wish to exclude and separate them by commas', 'wds')), array('type' => 'dropdown', 'name' => 'link_limit', 'title' => __('Maximum autolinks number limit', 'wds'), 'description' => __('This is the maximum number of autolinks that will be added to your posts.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 20)), array_merge(array(__('Unlimited', 'wds')), range(1, 20)))), array('type' => 'dropdown', 'name' => 'single_link_limit', 'title' => __('Maximum single autolink occurrence', 'wds'), 'description' => __('This is a number of single link replacement occurrences.', 'wds'), 'items' => array_combine(array_merge(array(0), range(1, 10)), array_merge(array(__('Unlimited', 'wds')), range(1, 10)))), array('type' => 'textarea', 'name' => 'customkey', 'title' => __('Custom Keywords', 'wds'), 'description' => __('Paste in the extra keywords you want to automaticaly link. Use comma to seperate keywords and add target url at the end. Use a new line for new url and set of keywords.
<br />Example:<br />
<code>WPMU DEV, plugins, themes, http://premium.wpmudev.org/<br />
WordPress News, http://wpmu.org/<br /></code>', 'wds')), array('type' => 'checkbox', 'name' => 'reduceload', 'title' => __('Other settings', 'wds'), 'items' => array('onlysingle' => __('Process only single posts and pages', 'wds'), 'allowfeed' => __('Process RSS feeds', 'wds'), 'casesens' => __('Case sensitive matching', 'wds'), 'customkey_preventduplicatelink' => __('Prevent duplicate links', 'wds'), 'target_blank' => __('Open links in new tab/window', 'wds'), 'rel_nofollow' => __('Autolinks <code>nofollow</code>', 'wds')))));
$contextual_help = '';
if (wds_is_wizard_step('5')) {
$settings = new WDS_Core_Admin_Tab($name, $title, $description, $fields, 'wds', $contextual_help);
}
}
示例6: testMapRawDataMapsFieldsCorrectly
/**
* @group mapper
* @covers \PHPExif\Mapper\Native::mapRawData
*/
public function testMapRawDataMapsFieldsCorrectly()
{
$reflProp = new \ReflectionProperty(get_class($this->mapper), 'map');
$reflProp->setAccessible(true);
$map = $reflProp->getValue($this->mapper);
// ignore custom formatted data stuff:
unset($map[\PHPExif\Mapper\Native::DATETIMEORIGINAL]);
unset($map[\PHPExif\Mapper\Native::EXPOSURETIME]);
unset($map[\PHPExif\Mapper\Native::FOCALLENGTH]);
unset($map[\PHPExif\Mapper\Native::XRESOLUTION]);
unset($map[\PHPExif\Mapper\Native::YRESOLUTION]);
unset($map[\PHPExif\Mapper\Native::GPSLATITUDE]);
unset($map[\PHPExif\Mapper\Native::GPSLONGITUDE]);
// create raw data
$keys = array_keys($map);
$values = array();
$values = array_pad($values, count($keys), 'foo');
$rawData = array_combine($keys, $values);
$mapped = $this->mapper->mapRawData($rawData);
$i = 0;
foreach ($mapped as $key => $value) {
$this->assertEquals($map[$keys[$i]], $key);
$i++;
}
}
示例7: getDocs
public function getDocs()
{
if (!isset($this->meta['keyword'], $this->meta['docs'])) {
return [];
}
return array_combine($this->meta['keyword'], $this->meta['docs']);
}
示例8: buildSchema
function buildSchema($id)
{
$notInput = array('fieldset', 'textonly');
App::import('Model', 'Cforms.Cform');
$this->Cform = new Cform();
$cform = $this->Cform->find('first', array('conditions' => array('Cform.id' => $id), 'contain' => array('FormField', 'FormField.ValidationRule')));
$schema = array();
$validate = array();
foreach ($cform['FormField'] as &$field) {
if (!in_array($field['type'], $notInput)) {
$schema[$field['name']] = array('type' => 'string', 'length' => $field['length'], 'null' => null, 'default' => $field['default']);
if (!empty($field['ValidationRule'])) {
foreach ($field['ValidationRule'] as $rule) {
$validate[$field['name']][$rule['rule']] = array('rule' => $rule['rule'], 'message' => $rule['message'], 'allowEmpty' => $field['required'] ? false : true);
}
} elseif ($field['required']) {
$validate[$field['name']] = array('notBlank');
}
if (!empty($field['depends_on']) && !empty($field['depends_value'])) {
$dependsOn[$field['name']] = array('field' => $field['depends_on'], 'value' => $field['depends_value']);
}
$field['options'] = str_replace(', ', ',', $field['options']);
$options = explode(',', $field['options']);
$field['options'] = array_combine($options, $options);
}
}
$this->validate = $validate;
$this->_schema = $schema;
$this->dependsOn = isset($dependsOn) ? $dependsOn : array();
return $cform;
}
示例9: listAction
/**
* List all user groups of a single backend
*/
public function listAction()
{
$this->assertPermission('config/authentication/groups/show');
$this->createListTabs()->activate('group/list');
$backendNames = array_map(function ($b) {
return $b->getName();
}, $this->loadUserGroupBackends('Icinga\\Data\\Selectable'));
if (empty($backendNames)) {
return;
}
$this->view->backendSelection = new Form();
$this->view->backendSelection->setAttrib('class', 'backend-selection');
$this->view->backendSelection->setUidDisabled();
$this->view->backendSelection->setMethod('GET');
$this->view->backendSelection->setTokenDisabled();
$this->view->backendSelection->addElement('select', 'backend', array('autosubmit' => true, 'label' => $this->translate('Usergroup Backend'), 'multiOptions' => array_combine($backendNames, $backendNames), 'value' => $this->params->get('backend')));
$backend = $this->getUserGroupBackend($this->params->get('backend'));
if ($backend === null) {
$this->view->backend = null;
return;
}
$query = $backend->select(array('group_name'));
$filterEditor = Widget::create('filterEditor')->setQuery($query)->setSearchColumns(array('group', 'user'))->preserveParams('limit', 'sort', 'dir', 'view', 'backend')->ignoreParams('page')->handleRequest($this->getRequest());
$query->applyFilter($filterEditor->getFilter());
$this->setupFilterControl($filterEditor);
$this->view->groups = $query;
$this->view->backend = $backend;
$this->setupPaginationControl($query);
$this->setupLimitControl();
$this->setupSortControl(array('group_name' => $this->translate('Group'), 'created_at' => $this->translate('Created at'), 'last_modified' => $this->translate('Last modified')), $query);
}
示例10: lotteryWeighted
/**
* @param array $words 抽出対象の配列($weightsと要素数は同数)
* @param array $weights 重みの配列(要素はint型)
*
* @return mixed $word 抽出された要素
*
* @throws Exception Validationエラー時に投げられる例外
*/
function lotteryWeighted($words, $weights)
{
//Validation.
try {
foreach ($weights as $weight) {
if (!is_int($weight)) {
throw new Exception("Weights only type int.");
}
}
$targets = array_combine($words, $weights);
if (!$targets) {
throw new Exception("The number of elements does not match.");
}
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
//抽出
$sum = array_sum($targets);
$judgeVal = rand(1, $sum);
foreach ($targets as $word => $weight) {
if (($sum -= $weight) < $judgeVal) {
return $word;
}
}
}
示例11: SubClassClear
/**
* Delete all objects from SubClass
*
* @param int SubClassID
*/
function SubClassClear($SubClassID)
{
global $nc_core, $db, $MODULE_FOLDER;
// full info about this subclass
$SubClassID = intval($SubClassID);
$res = $db->get_row("SELECT `Catalogue_ID`, `Subdivision_ID`, `Class_ID` FROM `Sub_Class` WHERE `Sub_Class_ID` = '" . $SubClassID . "'", ARRAY_A);
if (nc_module_check_by_keyword("comments")) {
include_once $MODULE_FOLDER . "comments/function.inc.php";
// delete comment rules
nc_comments::dropRuleSubClass($db, $SubClassID);
// delete comments
nc_comments::dropComments($db, $SubClassID, "Sub_Class");
}
DeleteSubClassFiles($SubClassID, $res['Class_ID']);
// delete from message
$messages_id = $db->get_col("SELECT `Message_ID` FROM `Message" . $res['Class_ID'] . "` WHERE `Subdivision_ID` = '" . $res['Subdivision_ID'] . "' AND `Sub_Class_ID` = '" . $SubClassID . "'");
if (!empty($messages_id)) {
if ($db->query("SELECT * FROM `Message" . $res['Class_ID'] . "` WHERE `Message_ID` IN (" . join(", ", $messages_id) . ")")) {
$messages_data = array_combine($db->get_col(NULL, 0), $db->get_results(NULL));
}
// execute core action
$nc_core->event->execute("dropMessagePrep", $res['Catalogue_ID'], $res['Subdivision_ID'], $SubClassID, $res['Class_ID'], $messages_id, $messages_data);
$db->query("DELETE FROM `Message" . $res['Class_ID'] . "` WHERE `Message_ID` IN (" . join(", ", $messages_id) . ")");
// execute core action
$nc_core->event->execute("dropMessage", $res['Catalogue_ID'], $res['Subdivision_ID'], $SubClassID, $res['Class_ID'], $messages_id, $messages_data);
}
return;
}
示例12: buildForm
/**
* Builds the form.
*
* This method is called for each type in the hierarchy starting form the
* top most type. Type extensions can further modify the form.
*
* @see FormTypeExtensionInterface::buildForm()
*
* @param FormBuilderInterface $builder The form builder
* @param array $options The options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$entityId = $this->entityId;
$menu = $this->menu;
$menuItemclass = $this->menuItemClass;
$builder->add('parent', EntityType::class, array('class' => $menuItemclass, 'choice_label' => 'displayTitle', 'query_builder' => function (EntityRepository $er) use($entityId, $menu) {
$qb = $er->createQueryBuilder('mi')->where('mi.menu = :menu')->setParameter('menu', $menu)->orderBy('mi.lft', 'ASC');
if ($entityId) {
$qb->andWhere('mi.id != :id')->setParameter('id', $entityId);
}
return $qb;
}, 'attr' => array('class' => 'js-advanced-select', 'data-placeholder' => 'Select the parent menu item...'), 'multiple' => false, 'expanded' => false, 'required' => false, 'label' => 'Parent menu item'));
$builder->add('type', ChoiceType::class, array('choices' => array_combine(MenuItem::$types, MenuItem::$types), 'placeholder' => false, 'required' => true));
$locale = $this->locale;
$rootNode = $this->rootNode;
$builder->add('nodeTranslation', EntityType::class, array('class' => 'KunstmaanNodeBundle:NodeTranslation', 'choice_label' => 'title', 'query_builder' => function (EntityRepository $er) use($locale, $rootNode) {
$qb = $er->createQueryBuilder('nt')->innerJoin('nt.publicNodeVersion', 'nv')->innerJoin('nt.node', 'n')->where('n.deleted = 0')->andWhere('nt.lang = :lang')->setParameter('lang', $locale)->andWhere('nt.online = 1')->orderBy('nt.title', 'ASC');
if ($rootNode) {
$qb->andWhere('n.lft >= :left')->andWhere('n.rgt <= :right')->setParameter('left', $rootNode->getLeft())->setParameter('right', $rootNode->getRight());
}
return $qb;
}, 'attr' => array('class' => 'js-advanced-select', 'data-placeholder' => 'Select the page to link to...'), 'multiple' => false, 'expanded' => false, 'required' => true, 'label' => 'Link page'));
$builder->add('title', TextType::class, array('required' => false));
$builder->add('url', TextType::class, array('required' => true));
$builder->add('newWindow');
}
示例13: init
/**
* Initializes the FTL Manager.
*
* @return void
*/
public static function init()
{
if (self::$_inited) {
return;
}
self::$_inited = TRUE;
self::$ci =& get_instance();
self::$context = new FTL_ArrayContext();
// Inlude array of module definition. This file is generated by module installation in Ionize.
// This file contains definition for installed modules only.
include APPPATH . 'config/modules.php';
// Put modules arrays keys to lowercase
if (!empty($modules)) {
self::$module_folders = array_combine(array_map('strtolower', array_values($modules)), array_values($modules));
}
// Loads automatically all installed modules tags
foreach (self::$module_folders as $module) {
self::autoload_module_tags($module . '_Tags');
}
// Load automatically all TagManagers defined in /libraries/Tagmanager
$tagmanagers = glob(APPPATH . 'libraries/Tagmanager/*' . EXT);
foreach ($tagmanagers as $tagmanager) {
self::autoload(array_pop(explode('/', $tagmanager)));
}
self::add_globals('TagManager');
self::add_tags();
self::add_module_tags();
}
示例14: get
/**
* Get Cache Value
*
* @param mixed $id
* @return mixed
*/
public function get($id)
{
if (is_string($id)) {
return $this->conn->get($id);
}
return array_combine($id, $this->conn->mGet($id));
}
示例15: getMargins
public function getMargins($list = null)
{
if (!$list) {
return $this->margins;
}
return array_intersect_key($this->margins, array_combine($list, $list));
}