Convert an Array or Object keys to new name by an array index.

@param   mixed $origin Array or Object to convert.
@param   mixed $map    Array or Object index for convert.

@return  mixed Mapped array or object.
777164
public static function mapKey($origin, $map = [])
    {
        $result = is_array($origin) ? [] : new \stdClass();

        foreach ((array) $origin as $key => $val) {
            $newKey = self::getValue($map, $key);

            if ($newKey) {
                self::setValue($result, $newKey, $val);
            } else {
                self::setValue($result, $key, $val);
            }
        }

        return $result;
    }
88163
public function renameMany(array $map) : Assoc
    {
        $pairs = array_map(function ($a, $b) {
            return [$a, $b];
        }, array_keys($map), array_values($map));

        return array_reduce($pairs, function ($that, $pair) {
            list ($from, $to) = $pair;

            return $that->rename($from, $to);
        }, $this);
    }
285679
private static function _oidReverseMap(): array
    {
        static $map;
        if (!isset($map)) {
            $map = array();
            // for eatch attribute type
            foreach (self::MAP_OID_TO_NAME as $oid => $names) {
                // for primary name and aliases
                foreach ($names as $name) {
                    $map[strtolower($name)] = $oid;
                }
            }
        }
        return $map;
    }
751102
public static function arrayToObject($array,$obj,$maps=[])
    {
        if(is_array($array) && is_object($obj)){
            foreach($array as $key=>$value){
                $propertyName=$key;
                if(array_key_exists($key, $maps)){
                    $propertyName=$maps[$key];
                }
                if(property_exists($obj,$propertyName)){
                    $obj->$propertyName=$value;
                }
            }
            return true;
        }
        return false;
    }
225351
static function fromJson(object $map): self {
    return new static(
      isset($map->functionName) && is_string($map->functionName) ? $map->functionName : '',
      isset($map->lineNumber) && is_int($map->lineNumber) ? $map->lineNumber : 0,
      isset($map->executionCount) && is_int($map->executionCount) ? $map->executionCount : 0
    );
  }
399396
public static function extractPrefix(string $prefix, $origin, $target = null)
    {
        $target = is_object($target) ? (object) $target : (array) $target;

        foreach ((array) $origin as $key => $val) {
            $key = $prefix . $key;

            if (!Arr::get($target, $key)) {
                $target = Arr::set($target, $key, $val);
            }
        }

        return $target;
    }
719412
private function setMap(array $map)
    {
        // Resets (overwrites) map.
        $this->map = [];
        foreach ($map as $type => $className) {
            $this->addClassToMap($type, $className);
        }
        return $this;
    }
968003
public function provide(
        string $reference,
        array $map = []
    ) {
        $request = $this->requestType == self::CURRENT_REQUEST
            ? $this
                ->requestStack
                ->getCurrentRequest()
            : $this
                ->requestStack
                ->getMasterRequest();

        if ($request instanceof Request) {
            foreach ([
                '~' => $request->attributes,
                '#' => $request->request,
                '?' => $request->query,
            ] as $symbol => $parameterBag) {
                $value = $this->resolveValueFromParameterBag(
                    $parameterBag,
                    $symbol,
                    $reference
                );

                if ($value !== $reference) {
                    return is_array($map) && isset($map[$value])
                        ? $map[$value]
                        : $value;
                }
            }
        }

        return $reference;
    }
702197
protected function optimizeLooseMap(array $map)
	{
		foreach ($map as $k => $v)
		{
			if ($k === $v)
			{
				unset($map[$k]);
			}
		}

		return $map;
	}
977255
protected function doMerge($object, array $dataObject, array $mapping = [])
    {
        if (count($mapping)) {
            foreach ($mapping as $field => $params) {
                if (is_string($params)) {
                    // Tries to decode if params is a string, so we can have a mapping information stringified in JSON
                    $params = json_decode($params, true);
                }
                if (!is_array($params)) {
                    // Allows anything to be transformed into an array
                    // If we used json_decode, "null" will be returned and then it'll become an empty array
                    // Although $params should be either "1", "true" or an array, even empty
                    $params = [];
                }
                if (array_key_exists($field, $dataObject)) {
                    $this->mergeField($field, $object, $dataObject[$field], $params);
                } else {
                    throw new \InvalidArgumentException(
                        sprintf(
                            'If you want to specify "%s" as an mergeable field, then you must have to set it in your data object.',
                            $field
                        )
                    );
                }
            }
        } else {
            foreach ($dataObject as $field => $value) {
                $this->mergeField($field, $object, $value);
            }
        }

        return $object;
    }
145964
private function _mapKeyIndex($arr,$keys)
    {
        $maps = array();
        foreach ($arr as $index=>$row) {
            $key = "n";
            foreach ($keys as $cName) {
                $key.=$row[$cName];
            }
            if (!isset($maps[$key])) {
                $maps[$key] = array();
            }
            array_push($maps[$key], $index);
        }
        return $maps;
    }
735146
public static function hashMap($map)
    {
        $cache = '';
        foreach ($map as $key => $value) {
            $cache .= 0xAB01 . $key . 0xAB02;
            if (is_array($value)) {
                $cache .= 0xAB04 . static::hashMap($value);
            } else {
                $cache .= 0xAB03 . $value;
            }
        }
        return md5($cache);
    }
34079
protected function getRoleIdentifierMap(array $map)
    {
        $rolesFromPolicy = $this->loadRolesFromPolicyFiles();

        foreach ($rolesFromPolicy as $newRoleIdentifier) {
            $map[substr($newRoleIdentifier, strrpos($newRoleIdentifier, ':') + 1)] = $newRoleIdentifier;
        }

        $map['Anonymous'] ='Anonymous';
        $map['Everybody'] = 'Everybody';

        return $map;
    }
619659
public function addAuthorMap($mapping)
    {
        foreach ($mapping as $author => $aliases) {
            if (\is_array($aliases)) {
                foreach ($aliases as $alias) {
                    $this->aliasAuthor($alias, $author);
                }
            } else {
                $this->aliasAuthor($aliases, $author);
            }
        }

        return $this;
    }
357354
public function collect(Map $map, array $domEventsOnce = [])
    {
        return $this->collectValues($map->getEventManager()->getDomEventsOnce(), $domEventsOnce);
    }
503030
protected function getDataFromMap(ParentChildMap $map) : array
    {
        /** @var Row[] $parentRows */
        $parentRows = [];
        /** @var object[] $children */
        $children = [];

        foreach ($map->getItems() as $key => $item) {
            if ($item->getChild()) {
                $parentRows[$key] = $item->getParent();
                $children[$key]   = $item->getChild();
            }
        }

        return array($parentRows, $children);
    }
368319
protected function getDefaultRequestHeaders($host, $key, $origin)
    {
        return [
            self::HEADER_HOST => $host,
            self::HEADER_UPGRADE => self::UPGRADE_VALUE,
            self::HEADER_CONNECTION => self::CONNECTION_VALUE,
            self::HEADER_KEY => $key,
            self::HEADER_ORIGIN => $origin,
            self::HEADER_VERSION => $this->getVersion(),
        ];
    }