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


PHP ArrayUtils::inArray方法代码示例

本文整理汇总了PHP中Zend\Stdlib\ArrayUtils::inArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::inArray方法的具体用法?PHP ArrayUtils::inArray怎么用?PHP ArrayUtils::inArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Stdlib\ArrayUtils的用法示例。


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

示例1: renderOptions

 /** {@inheritdoc} */
 public function renderOptions(array $options, array $selectedOptions = array())
 {
     $escapeHtml = $this->getEscapeHtmlHelper();
     $optionStrings = array();
     foreach ($options as $option) {
         $this->validTagAttributes = $this->validOptionAttributes;
         if (\Zend\Stdlib\ArrayUtils::inArray($option, $selectedOptions)) {
             $attributes = ' selected="selected"';
         } else {
             $attributes = '';
         }
         $optionStrings[] = sprintf('<option%s>%s</option>', $attributes, $escapeHtml($option));
     }
     return "\n" . implode("\n", $optionStrings) . "\n";
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:16,代码来源:FormSelectSimple.php

示例2: setOption

 /**
  * Option setter with validation
  * If option can have the specified value then it is set, otherwise this method throws exception
  *
  * Tip: call it into your setter methods.
  *
  * @param $key
  * @param $value
  * @return $this
  * @throws Exception\DomainException
  * @throws Exception\InvalidArgumentException
  */
 protected function setOption($key, $value)
 {
     if (!isset($this->config[$key])) {
         throw new Exception\DomainException(sprintf('Option "%s" does not exist; available options are (%s)', $key, implode(', ', array_map(function ($opt) {
             return '"' . $opt . '"';
         }, array_keys($this->config)))));
     }
     if (!ArrayUtils::isList($this->config[$key], false)) {
         throw new Exception\DomainException(sprintf('Option "%s" does not have a list of allowed values', $key));
     }
     if (!ArrayUtils::inArray($value, $this->config[$key], true)) {
         throw new Exception\InvalidArgumentException(sprintf('Option "%s" can not be set to value "%s"; allowed values are (%s)', $key, $value, implode(', ', array_map(function ($val) {
             return '"' . $val . '"';
         }, $this->config[$key]))));
     }
     $this->options[$key] = $value;
     return $this;
 }
开发者ID:leodido,项目名称:conversio,代码行数:30,代码来源:OptionsMap.php

示例3: renderOptions

 /**
  * Render an array of options
  *
  * Individual options should be of the form:
  *
  * <code>
  * array(
  *     'value'    => 'value',
  *     'label'    => 'label',
  *     'disabled' => $booleanFlag,
  *     'selected' => $booleanFlag,
  * )
  * </code>
  *
  * @param  array $options
  * @param  array $selectedOptions Option values that should be marked as selected
  * @return string
  */
 public function renderOptions(array $options, array $selectedOptions = array())
 {
     $template = '<option %s>%s</option>';
     $optionStrings = array();
     $escapeHtml = $this->getEscapeHtmlHelper();
     foreach ($options as $key => $optionSpec) {
         $value = '';
         $label = '';
         $selected = false;
         $disabled = false;
         if (is_scalar($optionSpec)) {
             $optionSpec = array('label' => $optionSpec, 'value' => $key);
         }
         if (isset($optionSpec['options']) && is_array($optionSpec['options'])) {
             $optionStrings[] = $this->renderOptgroup($optionSpec, $selectedOptions);
             continue;
         }
         if (isset($optionSpec['value'])) {
             $value = $optionSpec['value'];
         }
         if (isset($optionSpec['label'])) {
             $label = $optionSpec['label'];
             unset($optionSpec['label']);
         }
         if (isset($optionSpec['selected'])) {
             $selected = $optionSpec['selected'];
         }
         if (isset($optionSpec['disabled'])) {
             $disabled = $optionSpec['disabled'];
         }
         if (ArrayUtils::inArray($value, $selectedOptions)) {
             $selected = true;
         }
         if (null !== ($translator = $this->getTranslator())) {
             $label = $translator->translate($label, $this->getTranslatorTextDomain());
         }
         $attributes = array_merge($optionSpec, compact('value', 'selected', 'disabled'));
         $this->validTagAttributes = $this->validOptionAttributes;
         $optionStrings[] = sprintf($template, $this->createAttributesString($attributes), $escapeHtml($label));
     }
     return implode("\n", $optionStrings);
 }
开发者ID:gridguyz,项目名称:zork,代码行数:60,代码来源:FormSelect.php


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