Asserts that an array does not contain duplicates regarding a member.
Throws {@see \FeaturePhp\Helper\ArrayException} if duplicates are found.
@param array $_array
@param callable $key
@return array
509176
public static function assertNoDuplicates($_array, $key) {
        $array = $_array;
        while (count($array) > 0) {
            $element = $array[0];
            $array = array_slice($array, 1);
            $value = call_user_func(array($element, $key));
            if (self::findByKey($array, $key, $value))
                throw new ArrayException("duplicate found for \"$value\"");
        }
        return $_array;
    }
858813
public static function remove(array $array, string $key): array
    {
        // Extract key/path.
        $keyLast = Str::last($key, '.');
        $key = Str::removeLast($key, '.');

        // If found, remove element.
        $arrayElement = &self::dataByPath($array, $key, false, 'not.found');
        if ($arrayElement !== 'not.found') {
            if (array_key_exists($keyLast, $arrayElement)) {
                unset($arrayElement[$keyLast]);
            }
        }

        return $array;
    }
716958
public static function unique($array)
    {
        $results = [];
        if (self::isMulti($array)) {
            $array = self::multiToAssoc($array);
            foreach ($array as $key => $value) {
                $results[] = $value;
            }

            return array_unique($array);
        }

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

        foreach ($keys as $k) {

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

        return $array = $this->cleanString($array, $replaceWith);
    }
1163195
protected static function array_key_exists( $key, $array, $useIsset = false )
    {
        if ( !is_array( $key ) )
        {
            $key = array($key);
        }

        foreach ( $key as $_key )
        {
            if ( ( $useIsset && isset( $array[$_key] ) ) || array_key_exists( $_key, $array ) )
            {
                return $_key;
            }
        }

        return false;
    }
890545
public static function assignByKey($array, $key, $group = false)
    {

        if (empty($array)) return $array;

        $res = array();
        foreach ($array as $subthing) {
            $idx = null;
            if (is_object($subthing) && property_exists($subthing, $key)) {
                $idx = $subthing->$key;
            } elseif (is_array($subthing) && isset($subthing[$key])) {
                $idx = $subthing[$key];
            }
            if ($idx !== null) {
                if (!$group) {
                    $res[$idx] = $subthing;
                } else {
                    if (!isset($res[$idx])) $res[$idx] = array();
                    $res[$idx][] = $subthing;
                }
            }
        }

        return $res;
    }
871246
public static function getPrevKey($key, array $array) {
		$keys = array_keys($array);
		$found_index = array_search($key, $keys);
		if($found_index === false || $found_index === 0)
			return false;
		return $keys[$found_index - 1];
	}
252279
public static function exists($key, $array)
    {
        if (!is_array($array)) {
            return false;
        }
        if ($key == '') {
            return is_array($array) && array_key_exists((string)$key, $array);
        }
        return self::parseAndValidateKeys($key, $array)['isExists'];
    }
41643
private function hasArrayDuplicates($array)
    {
        $compare = array();
        foreach ($array as $element) {
            // duplicate element found
            if (in_array($element, $compare, true)) {
                return true;
            } else {
                // add element to temporary array to check for duplicates
                $compare [] = $element;
            }
        }

        return false;
    }
499527
public function key_search( array $array, $key, $value ) {
		foreach ( $array as $key => $a ) {
			if ( isset( $a[ $key ] ) && $a[ $key ] == $value ) {
				return $key;
			}
		}

		return false;
	}
564323
protected function isArrayHasKeys($array = [], $keys = []) {
		foreach ($keys as $key) {
			if (!ArrayHelper::getValue($array, $key, false)) {
				return false;
			}
		}

		return true;
	}
1104252
public static function has($array, $keys)
	{
		if(is_null($keys) || !$array)
			return false;

		$keys = static::toArray($keys);

		if($keys === [])
			return false;

		foreach ($keys as $key) {
			$subKeyArray = $array;

			if (static::exists($array, $key))
				continue;

			foreach (static::toKey($key) as $segment) {
				if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment))
					$subKeyArray = $subKeyArray[$segment];
				else
					return false;
			}
		}

		return true;
	}
1159773
public static function reduceToElementsWithKey($array, $key) {

        if ($array instanceof AssociativeArray) {
            $array = $array->toArray();
        }

        $targetArray = array();

        foreach ($array as $itemKey => $value) {

            if ($itemKey == $key) {
                $targetArray[$key] = $value;
            } else if (is_array($value) || $value instanceof AssociativeArray) {
                $subArray = ArrayUtils::reduceToElementsWithKey($value, $key);
                if (sizeof($subArray) > 0) {
                    $targetArray[$itemKey] = $subArray;
                }
            }

        }

        return $targetArray;

    }
1152007
public function hasKey($_)
    {
        try {
            $keys = array_reverse($this->getKeyArguments(func_get_args()));

            $array = $this->getArrayCopy();
            while (count($keys) > 0) {
                $key = array_pop($keys);
                if (! array_key_exists($key, $array)) {
                    return false;
                }
                $array = $array[$key];
            }
        } catch (Exception $exception) {
            return false;
        }

        return true;
    }
18642
public static function pluck(array $array, $key)
    {
        return array_map(
            function ($item) use ($key) {
                return is_object($item) ? $item->$key : $item[$key];
            },
            $array
        );
    }
165104
public static function getAllValuesOfKey(array $array, $key)
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return null;
        }

        $values = [];

        foreach ($array as $index => $value) {
            if ($index === $key) {
                $values[] = $value;

                continue;
            }

            if (is_array($value)) {
                $recursiveValues = self::getAllValuesOfKey($value, $key);

                if (!empty($recursiveValues)) {
                    $merged = array_merge($values, $recursiveValues);
                    $values = $merged;
                }
            }
        }

        return $values;
    }
1164492
public function arrayCopy(array $array)
    {
        $copy = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $copy[ $key ] = $this->arrayCopy($value);
            } elseif (is_object($value)) {
                $copy[ $key ] = clone $value;
            } else {
                $copy[ $key ] = $value;
            }
        }

        return $copy;
    }