Exchange the array for another one.

@param  array|ArrayObject $data

@throws \InvalidArgumentException
@return array
552072
public function exchangeArray($data)
    {
        if (!is_array($data) && !is_object($data)) {
            throw new \InvalidArgumentException('Passed variable is not an array or object, using empty array instead');
        }

        if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) {
            $data = $data->getArrayCopy();
        }

        if (!is_array($data)) {
            $data = (array) $data;
        }

        $storage = $this->storage;

        $this->storage = $data;

        return $storage;
    }
128423
public function exchangeArray($data)
    {
        foreach ($data as $property => $value) {
            if (isset($this->$property)) {
                $method = 'set' . ucfirst($property);
                $this->$method($value);
            }
        }
    }
1111667
public static function normalize($data)
    {
        $result = [];

        foreach ($data as $key => $value) {
            if (!is_int($key)) {
                $result[$key] = $value;
                continue;
            }
            if (!is_scalar($value)) {
                throw new Exception("Invalid array format, a value can't be normalized");
            }
            $result[$value] = null;
        }
        return $result;
    }
1283792
protected function asArray($data)
	{
		$array = array();

		if (is_object($data))
		{
			$data = get_object_vars($data);
		}

		foreach ($data as $k => $v)
		{
			if (is_object($v) || is_array($v))
			{
				$array[$k] = $this->asArray($v);
			}
			else
			{
				$array[$k] = $v;
			}
		}

		return $array;
	}
1257315
protected function dataToArray (array $data) {
        $result = [];
        foreach ($data as $key => $value) {
            if ($value instanceof ApiEntity) {
                $result[$key] = $value->toArray();
            } else if (is_array($value)) {
                $result[$key] = $this->dataToArray($value);
            } else {
                $result[$key] = $value;
            }
        }
        return $result;
    }
1271030
public function readFromArray(array $data) {
        $callback = 
        function ($v) {
            if ((!isset($v[0])) || (!isset($v[1]))) {
                throw new \InvalidArgumentException('Mismatch in the number of x and y in the dataset.');
            } else {
                $this->xVector[] = $v[0];
                $this->yVector[] = $v[1];
            }
        };    
        array_walk($data, $callback);
    }
195840
protected function assignFromArray($data)
    {
        if (!is_array($data)) {
            throw new \InvalidArgumentException(
                "Invalid data type: argument should be array, '" .gettype($name) . "' given."
            );
        }

        foreach ($data as $key => $value) {
            $this->assign($key, $value);
        }
    }
563336
public function fill($object, array $data)
    {
        if (! $object instanceof ConversionInterface) {
            throw new InvalidArgumentException(sprintf(
                'Invalid object "%s" provided; must be an instance of "%s".',
                is_object($object) ? get_class($object) : gettype($object),
                ConversionInterface::CLASS
            ));
        }
        $object->fromArray($data);
    }
390364
public static function arrayToObject($data)
    {
        if (is_array($data)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            $self_name = 'self::' . __FUNCTION__;

            return (object)array_map($self_name, $data);
        } else {
            // Return object
            return $data;
        }
    }
884369
public static function deserializeObject(array $data)
    {
        $subAttributes = [];
        if (isset($data['subAttributes'])) {
            foreach ($data['subAttributes'] as $subAttribute) {
                $subAttributes[] = static::deserializeObject($subAttribute);
            }
        }
        $result = new static(
            $data['name'],
            $data['type'],
            $data['multiValued'],
            $data['required'],
            isset($data['description']) ? $data['description'] : null,
            $subAttributes,
            isset($data['canonicalValues']) ? $data['canonicalValues'] : [],
            isset($data['caseExact']) ? $data['caseExact'] : false,
            $data['mutability'],
            $data['returned'],
            isset($data['uniqueness']) ? $data['uniqueness'] : null,
            isset($data['referenceTypes']) ? $data['referenceTypes'] : []
        );

        return $result;
    }
1105283
protected function rename(array $data): array
    {
        $result = [];
        foreach ($data as $dataItem) {
            list($keyId, $dataTmp) = $this->getKeyValue($dataItem);

            if ($keyId === null) {
                $result[] = $dataTmp;
            } else {
                $result[$keyId] = $dataTmp;
            }
        }

        return $result;
    }
1315547
public static function unserializePublicKey(string $data): array
    {
        $data = bin2hex($data);
        if (mb_substr($data, 0, 2, '8bit') !== '04') {
            throw new \InvalidArgumentException('Invalid data: only uncompressed keys are supported.');
        }
        $data = mb_substr($data, 2, null, '8bit');
        $dataLength = self::safeStrlen($data);

        return [
            hex2bin(mb_substr($data, 0, $dataLength / 2, '8bit')),
            hex2bin(mb_substr($data, $dataLength / 2, null, '8bit')),
        ];
    }
91126
protected function _toArray($data)
    {
        $array = array();

        foreach ($data as $key => $value) {
            if (is($value, 'AnDomainBehaviorSerializable')) {
                $array[$key] = $value->toSerializableArray();
            } elseif (is_array($value)) {
                $array[$key] = $this->_toArray($value);
            } else {
                $array[$key] = $value;
            }
        }

        return $array;
    }
921049
public function toObject(array $data)
    {
        $data = json_decode(json_encode($data));

        if ($data === []) {
            $data = new \StdClass();
        }

        return $data;
    }
982240
protected function asArray($data = []): array
    {
        if ($data instanceof Collection) {
            $data = $data->all();
        } elseif ($data instanceof Arrayable) {
            $data = $data->toArray();
        }

        return $data;
    }
595723
public function fromArray($data)
    {
        foreach ($data as $param => $value) {
            if (!method_exists($this, 'set' . ucfirst($param))) {
                continue;
            }
            $this->{'set' . ucfirst($param)}($value);
        }
        return $this;
    }
208204
protected static function getFirstRow(array $data)
    {
        if (empty($data)) {
            throw new \InvalidArgumentException('Empty data.');
        }

        list($first) = $data;

        if (!is_array($first)) {
            throw new \InvalidArgumentException('$data is not an array of array.');
        }

        return $first;
    }