Flattens an array to key => value.

@todo: milo - 20142901 - If you plan to extend phing and add a new fileparser, please move this to an abstract
class.

@param array $arrayToFlatten
188488
private function flattenArray(array $arrayToFlatten, $separator = '.', $flattenedKey = '')
    {
        $flattenedArray = [];
        foreach ($arrayToFlatten as $key => $value) {
            $tmpFlattendKey = (!empty($flattenedKey) ? $flattenedKey . $separator : '') . $key;
            // only append next value if is array and is an associative array
            if (is_array($value) && array_keys($value) !== range(0, count($value) - 1)) {
                $flattenedArray = array_merge(
                    $flattenedArray,
                    $this->flattenArray(
                        $value,
                        $separator,
                        $tmpFlattendKey
                    )
                );
            } else {
                $flattenedArray[$tmpFlattendKey] = $value;
            }
        }
        return $flattenedArray;
    }
649059
public static function setPropertyValues($object,$keyValueArray=[])
    {
        foreach ($keyValueArray as $name => $value){
            Convert::setPropertyValue($object, $name, $value);
        }
    }
1058681
public function setFromArray(array $fields)
    {
        foreach($fields as $key => $value)
        {
                $this->fields[$key] = $value;
                unset($key);
                unset($value);
        }
    }
692630
protected function denormalizeCollection(string $attribute, PropertyMetadata $propertyMetadata, Type $type, string $className, $value, ?string $format, array $context): array
    {
        if (!\is_array($value)) {
            throw new InvalidArgumentException(sprintf(
                'The type of the "%s" attribute must be "array", "%s" given.', $attribute, \gettype($value)
            ));
        }

        $collectionKeyType = $type->getCollectionKeyType();
        $collectionKeyBuiltinType = null === $collectionKeyType ? null : $collectionKeyType->getBuiltinType();

        $values = [];
        foreach ($value as $index => $obj) {
            if (null !== $collectionKeyBuiltinType && !\call_user_func('is_'.$collectionKeyBuiltinType, $index)) {
                throw new InvalidArgumentException(sprintf(
                        'The type of the key "%s" must be "%s", "%s" given.',
                        $index, $collectionKeyBuiltinType, \gettype($index))
                );
            }

            $values[$index] = $this->denormalizeRelation($attribute, $propertyMetadata, $className, $obj, $format, $this->createChildContext($context, $attribute));
        }

        return $values;
    }
1074067
public static function set(array & $array, $key, $value)
    {
        if (strpos($key, '.') !== false) {
            $keys = explode('.', $key);
            $topKey = array_shift($keys);

            if (!isset($array[$topKey]) || !is_array($array[$topKey])) {
                $array[$topKey] = [];
            }

            static::set($array[$topKey], implode('.', $keys), $value);
        } else {
            $array[$key] = $value;
        }
    }
717117
private function addValue($field, $value, $arrayKey)
    {
        $name = ':'. $arrayKey . $field;

        $this->names[$arrayKey][$field]      = $name;
        $this->parameters[$arrayKey][$field] = $value;
    }
403617
function addTo($to) {
		if(!is_array($to)) {
			$this->to[] = $to;
		}
		else {
			$this->to = array_merge($this->to, $to);
		}
	}
660247
public static function setNestedArrayValue(array &$array, array $parents, $value, $force = false)
    {
        $ref = &$array;
        foreach ($parents as $parent) {
            // PHP auto-creates container arrays and NULL entries without error if $ref
            // is NULL, but throws an error if $ref is set, but not an array.
            if ($force && isset($ref) && !is_array($ref)) {
                $ref = [];
            }
            $ref = &$ref[$parent];
        }
        $ref = $value;
    }
1328340
function arrayToStr(key, value) {
  if (isString(value) || isNumber(value)) return `${key}=${value}`;
  if (isString(value[0])) return `${key}=${value.join(':')}`;
  if (value && value.toString) return `${key}=${value.toString()}`;

  return value.map(val => arrayToStr(key, val));
}
948870
public static function set(array &$array, string $key, $value)
    {
        foreach (\explode('.', $key) as $k) {
            if (!isset($array[$k]) || !\is_array($array[$k])) {
                $array[$k] = [];
            }
            $array = &$array[$k];
        }

        $array = $value;
    }
214262
protected function preSerialization(array $value)
    {
        /** @var \NilPortugues\Api\Mapping\Mapping $mapping */
        foreach ($this->mappings as $class => $mapping) {
            RecursiveFilterHelper::deletePropertiesNotInFilter($this->mappings, $value, $class);
            RecursiveDeleteHelper::deleteProperties($this->mappings, $value, $class);
            $this->buildValidPropertyAlias($mapping);
            RecursiveRenamerHelper::renameKeyValue($this->mappings, $value, $class);
        }

        return $value;
    }
34246
protected static function dotNotationToArray($string, $value, array &$array)
    {
        $keys = explode('.', $string);
        foreach ($keys as $key) {
            $array = &$array[$key];
        }
        $array = ($value === 'true' || $value === 'false') ? $value === 'true' : $value;
    }
415449
private function convertArrayToArrayValue(array $value)
    {
        $values = [];
        foreach ($value as $val) {
            // ListValues may not contain nested ListValues.
            // Therefore, if an empty array is provided as part of an array,
            // we can encode it as an EntityValue.
            if (is_array($val) && empty($val)) {
                $val = (object) $val;
            }

            $values[] = $this->valueObject($val);
        }

        return [
            'arrayValue' => [
                'values' => $values
            ]
        ];
    }
351118
private function doAdd($value, $arrayAccess)
    {
        /* Initialize the collection before calling add() so this append operation
         * uses the appropriate key. Otherwise, we risk overwriting original data
         * when $newObjects are re-added in a later call to initialize().
         */
        if ($this->mapping->type === Type::MAP) {
            $this->initialize();
        }
        $arrayAccess ? $this->coll->offsetSet(null, $value) : $this->coll->add($value);
        $this->changed();

        if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) {
            $this->uow->unscheduleOrphanRemoval($value);
        }

        return true;
    }
780441
public static function flattenAssocArray(
        array $array,
        $format,
        $glue = null,
        $escape = false
    ) {
        $pairs = [];
        foreach ($array as $key => $val) {
            if ($escape) {
                $key = self::escape($key);
                $val = self::escape($val);
            }
            $pairs[] = sprintf($format, $key, $val);
        }

        //Return array if no glue provided
        if ($glue === null) {
            return $pairs;
        } else {
            return implode($glue, $pairs);
        }
    }
848846
private function handleNestedValue($key, $value, $setOnlyIfNotExists)
    {
        $array = $this->val();
        if (strpos($key, '.') !== false) {
            $keys = explode('.', trim($key, '.'), 2);
            if (!isset($array[$keys[0]])) {
                $array[$keys[0]] = [];
            }
            $targetArray = new ArrayObject($array[$keys[0]]);
            $targetArray->keyNested($keys[1], $value, $setOnlyIfNotExists);
            $this->keyNested($keys[0], $targetArray->val());
        } else {
            $array[$key] = $value;
            $this->val($array);
        }
    }
1041444
protected function addAttributeValue($value, $valueToAdd)
    {
        $valueToAdd = is_array($valueToAdd) ? $valueToAdd : [ $valueToAdd ];
        $value = is_array($value) ? $value : [ $value ];

        return array_merge($value, $valueToAdd);
    }