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


PHP ArrayLib::flatten方法代码示例

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


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

示例1: Field

 /**
  * Returns a readonly span containing the correct value.
  *
  * @param array $properties
  *
  * @return string
  */
 public function Field($properties = array())
 {
     $source = ArrayLib::flatten($this->getSource());
     $values = $this->getValueArray();
     // Get selected values
     $mapped = array();
     foreach ($values as $value) {
         if (isset($source[$value])) {
             $mapped[] = $source[$value];
         }
     }
     // Don't check if string arguments are matching against the source,
     // as they might be generated HTML diff views instead of the actual values
     if ($this->value && is_string($this->value) && empty($mapped)) {
         $mapped = array(trim($this->value));
         $values = array();
     }
     if ($mapped) {
         $attrValue = implode(', ', array_values($mapped));
         if (!$this->dontEscape) {
             $attrValue = Convert::raw2xml($attrValue);
         }
         $inputValue = implode(', ', array_values($values));
     } else {
         $attrValue = '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
         $inputValue = '';
     }
     $properties = array_merge($properties, array('AttrValue' => $attrValue, 'InputValue' => $inputValue));
     return parent::Field($properties);
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:37,代码来源:LookupField.php

示例2: testFlatten

 public function testFlatten()
 {
     $options = array('1' => 'one', '2' => 'two');
     $expected = $options;
     $this->assertEquals($expected, ArrayLib::flatten($options));
     $options = array('1' => array('2' => 'two', '3' => 'three'), '4' => 'four');
     $expected = array('2' => 'two', '3' => 'three', '4' => 'four');
     $this->assertEquals($expected, ArrayLib::flatten($options));
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:9,代码来源:ArrayLibTest.php

示例3: Field

 /**
  * Returns a readonly span containing the correct value.
  *
  * @param array $properties
  *
  * @return string
  */
 public function Field($properties = array())
 {
     $source = $this->getSource();
     // Normalize value to array to simplify further processing
     if (is_array($this->value) || is_object($this->value)) {
         $values = $this->value;
     } else {
         $values = array(trim($this->value));
     }
     $mapped = array();
     if ($source instanceof SQLMap) {
         foreach ($values as $value) {
             $mapped[] = $source->getItem($value);
         }
     } else {
         if ($source instanceof ArrayAccess || is_array($source)) {
             $source = ArrayLib::flatten($source);
             foreach ($values as $value) {
                 if (isset($source[$value])) {
                     $mapped[] = $source[$value];
                 }
             }
         } else {
             $mapped = array();
         }
     }
     // Don't check if string arguments are matching against the source,
     // as they might be generated HTML diff views instead of the actual values
     if ($this->value && !is_array($this->value) && !$mapped) {
         $mapped = array(trim($this->value));
         $values = array();
     }
     if ($mapped) {
         $attrValue = implode(', ', array_values($mapped));
         if (!$this->dontEscape) {
             $attrValue = Convert::raw2xml($attrValue);
         }
         $inputValue = implode(', ', array_values($values));
     } else {
         $attrValue = "<i>(none)</i>";
         $inputValue = '';
     }
     $properties = array_merge($properties, array('AttrValue' => $attrValue, 'InputValue' => $inputValue));
     return parent::Field($properties);
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:52,代码来源:LookupField.php

示例4: Field

 /**
  * Returns a readonly span containing the correct value.
  *
  * @param array $properties
  *
  * @return string
  */
 public function Field($properties = array())
 {
     $source = $this->getSource();
     // Normalize value to array to simplify further processing
     if (is_array($this->value) || is_object($this->value)) {
         $values = $this->value;
     } else {
         $values = array(trim($this->value));
     }
     $mapped = array();
     if ($source instanceof SQLMap) {
         foreach ($values as $value) {
             $mapped[] = $source->getItem($value);
         }
     } else {
         if ($source instanceof ArrayAccess || is_array($source)) {
             $source = ArrayLib::flatten($source);
             foreach ($values as $value) {
                 if (isset($source[$value])) {
                     $mapped[] = $source[$value];
                 }
             }
         } else {
             $mapped = array();
         }
     }
     // Don't check if string arguments are matching against the source,
     // as they might be generated HTML diff views instead of the actual values
     if ($this->value && !is_array($this->value) && !$mapped) {
         $mapped = array(trim($this->value));
         $values = array();
     }
     if ($mapped) {
         $attrValue = implode(', ', array_values($mapped));
         if (!$this->dontEscape) {
             $attrValue = Convert::raw2xml($attrValue);
         }
         $inputValue = implode(', ', array_values($values));
     } else {
         $attrValue = '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
         $inputValue = '';
     }
     return "<span class=\"readonly\" id=\"" . $this->id() . "\">{$attrValue}</span><input type=\"hidden\" name=\"" . $this->name . "\" value=\"" . $inputValue . "\" />";
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:51,代码来源:LookupField.php


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