You are here

public static function XmlHelper::simplifyElements in Helper 7

2 calls to XmlHelper::simplifyElements()
XmlHelper::parseElement in lib/XmlHelper.php
XmlHelper::parseElements in lib/XmlHelper.php
Convert a string of XML to an associative array.

File

lib/XmlHelper.php, line 85

Class

XmlHelper

Code

public static function simplifyElements(array &$elements) {
  $key_indexes = array();
  foreach ($elements as $index => $element) {
    $key_indexes[$element['key']][] = $index;
  }
  foreach ($elements as $index => $element) {
    if (!is_numeric($index) || !is_array($element) || !isset($element['key'])) {
      continue;
    }
    if (count($key_indexes[$element['key']]) > 1) {
      continue;
    }
    if (!empty($element['attributes'])) {
      continue;
    }

    // Replace it in the array.
    $elements = ArrayHelper::spliceAssociativeValues($elements, array(
      $element['key'] => $element['value'],
    ), $index);
    unset($elements[$index]);
  }
}