本文整理汇总了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));
}
示例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);
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
}
}
示例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;
}
}
}
示例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);
}
}
}
示例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.');
}