@param mixed $array
@param mixed $subArray
@param bool  $overwrite
@param bool  $ignoreIfExists

@return array
187974
public static function insertSubArray($array, $subArray, $overwrite = false, $ignoreIfExists = false)
    {
        // validate
        if (!is_bool($overwrite)) {
            throw new InvalidArgumentException('Overwrite indicator must be a boolean');
        }
        if (!is_bool($ignoreIfExists)) {
            throw new InvalidArgumentException('Ignore if exists indicator must be a boolean');
        }

        if (!is_array($subArray) || !is_array($array)) {
            // $subArray[$key] is leaf of the array
            if ($overwrite) {
                $array = $subArray;
            } elseif (!$ignoreIfExists) {
                throw new UnexpectedValueException('Sub-array already exists');
            }
        } else {
            $key = key($subArray);
            if (isset($array[$key]) || array_key_exists($key, $array)) {
                $array[$key] = self::insertSubArray($array[$key], $subArray[$key], $overwrite, $ignoreIfExists);
            } else {
                $array[$key] = $subArray[$key];
            }
        }

        return $array;
    }
20894
private function applyPrefix(array $array, $prefix = null)
    {
        if ($prefix === null) {
            return $array;
        }

        $result = [];
        foreach ($array as $key => $value) {
            $result[$prefix . self::PREFIX_GLUE . $key] = $value;
        }

        return $result;
    }
630551
public static function multisort($array, $conditions, $ignore_case = false)
	{
		$temp = array();
		$keys = array_keys($conditions);

		foreach($keys as $key)
		{
			$temp[$key] = static::pluck($array, $key, true);
			is_array($conditions[$key]) or $conditions[$key] = array($conditions[$key]);
		}

		$args = array();
		foreach ($keys as $key)
		{
			$args[] = $ignore_case ? array_map('strtolower', $temp[$key]) : $temp[$key];
			foreach($conditions[$key] as $flag)
			{
				$args[] = $flag;
			}
		}

		$args[] = &$array;

		call_fuel_func_array('array_multisort', $args);
		return $array;
	}
451177
private function cleanArrayKey($key, &$array, $replaceWith)
    {
        $keys = explode('.', $key);

        foreach ($keys as $k) {

            $array = &$array[$k];
        }

        return $array = $this->cleanString($array, $replaceWith);
    }
231500
public function copyToArray(array &$array)
    {
        $array['grantType']            = LanguageUtility::toString($this->grantType);
        $array['clientId']             = LanguageUtility::orZero($this->clientId);
        $array['subject']              = $this->subject;
        $array['scopes']               = $this->scopes;
        $array['accessTokenDuration']  = LanguageUtility::orZero($this->accessTokenDuration);
        $array['refreshTokenDuration'] = LanguageUtility::orZero($this->refreshTokenDuration);
        $array['properties']           = LanguageUtility::convertArrayOfArrayCopyableToArray($this->properties);
        $array['clientIdAliasUsed']    = $this->clientIdAliasUsed;
        $array['accessToken']          = $this->accessToken;
        $array['refreshToken']         = $this->refreshToken;
    }
425590
public function setRepositorySubscription(bool $subscribed = false, bool $ignored = false): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/subscription?:args',
            $this->getActivity()->getOwner(), $this->getActivity()->getRepo(), http_build_query([
                'subscribed' => $subscribed,
                'ignored'    => $ignored
            ])), Request::METHOD_PUT);
    }
1370202
public static function filterSuffixed($array, $suffix, $removeSuffix = true)
	{
		$return = array();
		foreach ($array as $key => $val)
		{
			if (preg_match('/' . $suffix . '$/', $key))
			{
				if ($removeSuffix === true)
				{
					$key = preg_replace('/' . $suffix . '$/', '', $key);
				}
				$return[$key] = $val;
			}
		}
		return $return;
	}
45544
public function copyFromArray(array &$array)
    {
        // grantType
        $this->setGrantType(
            GrantType::valueOf(
                LanguageUtility::getFromArray('grantType', $array)));

        // clientId
        $this->setClientId(
            LanguageUtility::getFromArray('clientId', $array));

        // subject
        $this->setSubject(
            LanguageUtility::getFromArray('subject', $array));

        // scopes
        $this->setScopes(
            LanguageUtility::getFromArray('scopes', $array));

        // accessTokenDuration
        $this->setAccessTokenDuration(
            LanguageUtility::getFromArray('accessTokenDuration', $array));

        // refreshTokenDuration
        $this->setRefreshTokenDuration(
            LanguageUtility::getFromArray('refreshTokenDuration', $array));

        // properties
        $properties = LanguageUtility::getFromArray('properties', $array);
        $this->setProperties(
            LanguageUtility::convertArrayToArrayOfArrayCopyable(
                $properties, __NAMESPACE__ . '\Property'));

        // clientIdAliasUsed
        $this->setClientIdAliasUsed(
            LanguageUtility::getFromArrayAsBoolean('clientIdAliasUsed', $array));

        // accessToken
        $this->setAccessToken(
            LanguageUtility::getFromArray('accessToken', $array));

        // refreshToken
        $this->setRefreshToken(
            LanguageUtility::getFromArray('refreshToken', $array));
    }
934636
public function indexBy($list, $property, $meta=null, $allowDupes=null, $ignoreNulls=null)
    {
        $allowDupes  = $allowDupes  !== null ? $allowDupes  : false;
        $ignoreNulls = $ignoreNulls !== null ? $ignoreNulls : true;

        if (!$list) {
            return [];
        }

        if ($meta) {
            $meta = !$meta instanceof Meta ? $this->mapper->getMeta($meta) : $meta;
        }
        else {
            if (!($first = current($list))) {
                throw new \UnexpectedValueException();
            }
            $meta = $this->mapper->getMeta(get_class($first));
        }

        $index = array();

        $props = $meta ? $meta->getProperties() : [];
        foreach ($list as $object) {
            $propDef = !isset($props[$property]) ? null : $props[$property];
            $value = !$propDef || !isset($propDef['getter']) 
                ? $object->{$property} 
                : call_user_func(array($object, $propDef['getter']));

            if ($value === null && $ignoreNulls) {
                continue;
            }
            if (!$allowDupes && isset($index[$value])) {
                throw new \UnexpectedValueException("Duplicate value for property $property");
            }
            $index[$value] = $object;
        }
        return $index;
    }
36245
public function toArray($ignore = ['revisions', 'site'])
    {
        $prefix = 'get';
        $properties = get_object_vars($this);
        $data = [];

        foreach ($properties as $property => $value) {
            // Check for ignore keys
            if (in_array($property, $ignore)) {
                continue;
            }

            $method = $prefix . ucfirst($property);

            if (method_exists($this, $method)) {
                $data[$property] = $this->$method();
            }
        }

        if (!in_array('revisions', $ignore)) {
            $data['revisions'] = $this->modelArrayToArray(
                $this->getRevisions()->toArray(),
                []
            );
        }

        if (!in_array('siteId', $ignore)) {
            $data['siteId'] = $this->getSiteId();
        }

        if (!in_array('createdDateString', $ignore)) {
            $data['createdDateString'] = $this->getCreatedDateString();
        }

        if (!in_array('lastPublishedString', $ignore)) {
            $data['lastPublishedString'] = $this->getLastPublishedString();
        }

        return $data;
    }
1060825
public static function removeKeys($array, $removeKeys)
    {
        $result = [];
        if (!is_array($removeKeys)) {
            $removeKeys = [$removeKeys];
        }
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $value = self::removeKeys($value, $removeKeys);
            }
            if (in_array($key, $removeKeys)) {
                continue;
            } else {
                $result[$key] = $value;
            }
        }
        return $result;
    }
130132
public function setVariables($variables, $overwrite = false)
    {
        if (is_array($variables) || $variables instanceof Traversable) {
            return parent::setVariables($variables, $overwrite);
        }

        if ($variables instanceof \JsonSerializable) {
            $variables = $variables->jsonSerialize();

            return parent::setVariables($variables, $overwrite);
        }

        if (is_object($variables) && method_exists($variables, 'toArray')) {
            $variables = $variables->toArray();

            return parent::setVariables($variables, $overwrite);
        }

        if (is_object($variables) && method_exists($variables, '_toArray')) {
            $variables = $variables->_toArray();

            return parent::setVariables($variables, $overwrite);
        }

        if (is_object($variables) && method_exists($variables, '__toArray')) {
            $variables = $variables->__toArray();

            return parent::setVariables($variables, $overwrite);
        }

        return parent::setVariables($variables, $overwrite);
    }
1306342
private function formatThrowableObjects(array $array)
    {
        array_walk_recursive($array, function (&$value) {
            if ($value instanceof \Throwable) {
                try {
                    $value = serialize($value);
                } catch (\Throwable $throwable) {
                    $value = $this->formatThrowable($value);
                }
            }
        });

        return $array;
    }
476905
public function merge(DataArrayInterface $dataArray, $overwrite = true)
    {
        foreach ($dataArray as $key => $value) {
            //http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html
            if (isset($this->value[$key])) {
                if (is_int($key)) {
                    $this->value[] = $value;
                } else if ($value instanceof self
                    && $this->value[$key] instanceof self) {
                    $this->value[$key]->merge($value);
                } else if ($overwrite) {
                    if ($value instanceof self) {
                        //new static for php 5.3. late static binding
                        //we need to do this since it is possible we are dealing
                        // with a derived class
                        $this->value[$key] = new static($value->toArray());
                    } else {
                        $this->value[$key] = $value;
                    }
                }
            } else {
                if ($value instanceof self) {
                    $this->value[$key] = new static($value->toArray());
                } else {
                    $this->value[$key] = $value;
                }
            }
        }

        return $this;
    }
155688
public static function pushDiff($array, $array2) {
		if (empty($array) && !empty($array2)) {
			return $array2;
		}
		if (!empty($array) && !empty($array2)) {
			foreach ($array2 as $key => $value) {
				if (!array_key_exists($key, $array)) {
					$array[$key] = $value;
				} else {
					if (is_array($value)) {
						$array[$key] = static::pushDiff($array[$key], $array2[$key]);
					}
				}
			}
		}
		return $array;
	}
936601
public static function flatten($array, $glue = ':', $reset = true, $indexed = true)
    {
        static $return = array();
        static $curr_key = array();

        if ($reset) {
            $return = array();
            $curr_key = array();
        }

        foreach ($array as $key => $val) {
            $curr_key[] = $key;
            if (is_array($val) and ($indexed or array_values($val) !== $val)) {
                static::flatten_assoc($val, $glue, false);
            } else {
                $return[implode($glue, $curr_key)] = $val;
            }
            array_pop($curr_key);
        }
        return $return;
    }
482350
protected function arrayFilterRecursive($array)
    {
        foreach ($array as &$value) {
            if (is_array($value)) {
                $value = $this->arrayFilterRecursive($value);
            }
        }

        return array_filter($array);
    }