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


PHP ArrayHelper::isAssociative方法代码示例

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


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

示例1: objectToString

 /**
  * Converts an object into an INI formatted string
  * - Unfortunately, there is no way to have ini values nested further than two
  * levels deep.  Therefore we will only go through the first two levels of
  * the object.
  *
  * @param   object  $object   Data source object.
  * @param   array   $options  Options used by the formatter.
  *
  * @return  string  INI formatted string.
  *
  * @since   1.0
  */
 public function objectToString($object, $options = array())
 {
     $options = array_merge(self::$options, $options);
     $local = array();
     $global = array();
     $variables = get_object_vars($object);
     $last = count($variables);
     // Assume that the first element is in section
     $in_section = true;
     // Iterate over the object to set the properties.
     foreach ($variables as $key => $value) {
         // If the value is an object then we need to put it in a local section.
         if (is_object($value)) {
             // Add an empty line if previous string wasn't in a section
             if (!$in_section) {
                 $local[] = '';
             }
             // Add the section line.
             $local[] = '[' . $key . ']';
             // Add the properties for this section.
             foreach (get_object_vars($value) as $k => $v) {
                 if (is_array($v) && $options['supportArrayValues']) {
                     $assoc = ArrayHelper::isAssociative($v);
                     foreach ($v as $array_key => $item) {
                         $array_key = $assoc ? $array_key : '';
                         $local[] = $k . '[' . $array_key . ']=' . $this->getValueAsINI($item);
                     }
                 } else {
                     $local[] = $k . '=' . $this->getValueAsINI($v);
                 }
             }
             // Add empty line after section if it is not the last one
             if (0 != --$last) {
                 $local[] = '';
             }
         } elseif (is_array($value) && $options['supportArrayValues']) {
             $assoc = ArrayHelper::isAssociative($value);
             foreach ($value as $array_key => $item) {
                 $array_key = $assoc ? $array_key : '';
                 $global[] = $key . '[' . $array_key . ']=' . $this->getValueAsINI($item);
             }
         } else {
             // Not in a section so add the property to the global array.
             $global[] = $key . '=' . $this->getValueAsINI($value);
             $in_section = false;
         }
     }
     return implode("\n", array_merge($global, $local));
 }
开发者ID:grlf,项目名称:eyedock,代码行数:62,代码来源:Ini.php

示例2: isAssociative

 /**
  * Method to determine if an array is an associative array.
  *
  * @param   array  $array  An array to test.
  *
  * @return  boolean  True if the array is an associative array.
  *
  * @since   11.1
  * @deprecated  4.0 Use Joomla\Utilities\ArrayHelper::isAssociative instead
  */
 public static function isAssociative($array)
 {
     return ArrayHelper::isAssociative($array);
 }
开发者ID:joomla-projects,项目名称:media-manager-improvement,代码行数:14,代码来源:arrayhelper.php

示例3: bindData

 /**
  * Method to recursively bind data to a parent object.
  *
  * @param   object   $parent     The parent object on which to attach the data values.
  * @param   mixed    $data       An array or object of data to bind to the parent object.
  * @param   boolean  $recursive  True to support recursive bindData.
  * @param   boolean  $allowNull  True to allow null values.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function bindData($parent, $data, $recursive = true, $allowNull = true)
 {
     // Ensure the input data is an array.
     $data = is_object($data) ? get_object_vars($data) : (array) $data;
     foreach ($data as $k => $v) {
         if (!$allowNull && !($v !== null && $v !== '')) {
             continue;
         }
         if ($recursive && (is_array($v) && ArrayHelper::isAssociative($v) || is_object($v))) {
             if (!isset($parent->{$k})) {
                 $parent->{$k} = new \stdClass();
             }
             $this->bindData($parent->{$k}, $v);
             continue;
         }
         $parent->{$k} = $v;
     }
 }
开发者ID:nkuitche,项目名称:registry,代码行数:30,代码来源:Registry.php

示例4: bindLevel

 /**
  * Method to bind data to the form for the group level.
  *
  * @param   string  $group  The dot-separated form group path on which to bind the data.
  * @param   mixed   $data   An array or object of data to bind to the form for the group level.
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function bindLevel($group, $data)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         if ($data instanceof Registry) {
             // Handle a Registry.
             $data = $data->toArray();
         } elseif ($data instanceof JObject) {
             // Handle a JObject.
             $data = $data->getProperties();
         } else {
             // Handle other types of objects.
             $data = (array) $data;
         }
     }
     // Process the input data.
     foreach ($data as $k => $v) {
         $level = $group ? $group . '.' . $k : $k;
         if ($this->findField($k, $group)) {
             // If the field exists set the value.
             $this->data->set($level, $v);
         } elseif (is_object($v) || ArrayHelper::isAssociative($v)) {
             // If the value is an object or an associative array, hand it off to the recursive bind level method.
             $this->bindLevel($level, $v);
         }
     }
 }
开发者ID:adjaika,项目名称:J3Base,代码行数:37,代码来源:form.php

示例5: bindData

 /**
  * Method to recursively bind data to a parent object.
  *
  * @param   object   $parent     The parent object on which to attach the data values.
  * @param   mixed    $data       An array or object of data to bind to the parent object.
  * @param   boolean  $recursive  True to support recursive bindData.
  *
  * @return  void
  *
  * @since   1.0
  */
 protected function bindData($parent, $data, $recursive = true)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         $data = get_object_vars($data);
     } else {
         $data = (array) $data;
     }
     foreach ($data as $k => $v) {
         if ($v === '' || $v === null) {
             continue;
         }
         if (is_array($v) && ArrayHelper::isAssociative($v) || is_object($v) && $recursive) {
             if (!isset($parent->{$k})) {
                 $parent->{$k} = new \stdClass();
             }
             $this->bindData($parent->{$k}, $v);
         } else {
             $parent->{$k} = $v;
         }
     }
 }
开发者ID:ZerGabriel,项目名称:joomla-framework,代码行数:33,代码来源:Registry.php

示例6: bindData

 /**
  * Method to recursively bind data to a parent object.
  *
  * @param   object  $parent  The parent object on which to attach the data values.
  * @param   mixed   $data    An array or object of data to bind to the parent object.
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function bindData($parent, $data)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         $data = get_object_vars($data);
     } else {
         $data = (array) $data;
     }
     foreach ($data as $k => $v) {
         if (is_array($v) && ArrayHelper::isAssociative($v) || is_object($v)) {
             $parent->{$k} = new stdClass();
             $this->bindData($parent->{$k}, $v);
         } else {
             $parent->{$k} = $v;
         }
     }
 }
开发者ID:Alibek,项目名称:joomla-platform-namespace-example,代码行数:27,代码来源:Registry.php

示例7: bindLevel

 /**
  * Method to bind data to the form for the group level.
  *
  * @param   string  $group  The dot-separated form group path on which to bind the data.
  * @param   mixed   $data   An array or object of data to bind to the form for the group level.
  *
  * @return  void
  *
  * @since   11.1
  */
 protected function bindLevel($group, $data)
 {
     // Ensure the input data is an array.
     settype($data, 'array');
     // Process the input data.
     foreach ($data as $k => $v) {
         if ($this->findField($k, $group)) {
             // If the field exists set the value.
             $this->data->set($group . '.' . $k, $v);
         } elseif (is_object($v) || ArrayHelper::isAssociative($v)) {
             // If the value is an object or an associative array, hand it off to the recursive bind level method
             $this->bindLevel($group . '.' . $k, $v);
         }
     }
 }
开发者ID:Alibek,项目名称:joomla-platform-namespace-example,代码行数:25,代码来源:Form.php

示例8: testIsAssociative

 /**
  * Test the ArrayHelper::isAssociate method.
  *
  * @return  void
  *
  * @since   1.0
  * @sovers  ArrayHelper::isAssociative
  */
 public function testIsAssociative()
 {
     $this->assertThat(ArrayHelper::isAssociative(array(1, 2, 3)), $this->isFalse(), 'Line: ' . __LINE__ . ' This array should not be associative.');
     $this->assertThat(ArrayHelper::isAssociative(array('a' => 1, 'b' => 2, 'c' => 3)), $this->isTrue(), 'Line: ' . __LINE__ . ' This array should be associative.');
     $this->assertThat(ArrayHelper::isAssociative(array('a' => 1, 2, 'c' => 3)), $this->isTrue(), 'Line: ' . __LINE__ . ' This array should be associative.');
 }
开发者ID:beingsane,项目名称:quickcontent,代码行数:14,代码来源:ArrayHelperTest.php


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