src/Utils/Data.php
public static function flattenData(array $data, $prefix = NULL, $label = array()) {
    $flattened_data = array();
    if (isset($data['#label'])) {
      $label[] = $data['#label'];
    }
    // Each element is either a text (has #text property defined) or has children,
    // not both.
    if (!empty($data['#text'])) {
      $flattened_data[$prefix] = $data;
      $flattened_data[$prefix]['#parent_label'] = $label;
    }
    else {
      $prefix = isset($prefix) ? $prefix . self::ARRAY_DELIMITER : '';
      foreach (self::elementChildren($data) as $key) {
        $flattened_data += self::flattenData($data[$key], $prefix . $key, $label);
      }
    }
    return $flattened_data;
  }
public static function flattenData(array $data, $prefix = NULL, $label = array()) {
    $flattened_data = array();
    if (isset($data['#label'])) {
      $label[] = $data['#label'];
    }
    // Each element is either a text (has #text property defined) or has children,
    // not both.
    if (!empty($data['#text'])) {
      $flattened_data[$prefix] = $data;
      $flattened_data[$prefix]['#parent_label'] = $label;
    }
    else {
      $prefix = isset($prefix) ? $prefix . self::ARRAY_DELIMITER : '';
      foreach (self::elementChildren($data) as $key) {
        $flattened_data += self::flattenData($data[$key], $prefix . $key, $label);
      }
    }
    return $flattened_data;
  }
public static function flattenData ( array $ data , $ prefix = NULL , $ label = array ( ) ) { $ flattened_data = array ( ) ; if ( isset ( $ data [ '#label' ] ) ) { $ label [ ] = $ data [ '#label' ] ; } // Each element is either a text (has #text property defined) or has children, // not both. if ( ! empty ( $ data [ '#text' ] ) ) { $ flattened_data [ $ prefix ] = $ data ; $ flattened_data [ $ prefix ] [ '#parent_label' ] = $ label ; } else { $ prefix = isset ( $ prefix ) ? $ prefix . self :: ARRAY_DELIMITER : '' ; foreach ( self :: elementChildren ( $ data ) as $ key ) { $ flattened_data += self :: flattenData ( $ data [ $ key ] , $ prefix . $ key , $ label ) ; } } return $ flattened_data ; }
Converts a nested data array into a flattened structure with a combined key.

This function can be used by translators to help with the data conversion.

Nested keys will be joined together using a colon, so for example
$data['key1']['key2']['key3'] will be converted into
$flattened_data['key1][key2][key3'].

@param array $data
The nested array structure that should be flattened.

@param string $prefix
Internal use only, indicates the current key prefix when recursing into
the data array.

@param array $label
Internal use only.

@return array
The flattened data array.

@see TableauXliffSerializer::unflattenData()
Converts a nested data array into a flattened structure with a combined key .