public static function extract(
        array $input,
        $keyIndex,
        $valueIndex,
        string $duplicateBehavior = 'takeLast'
    ) : array {
        if (!in_array($duplicateBehavior, ['takeFirst', 'takeLast', 'throw'])) {
            throw new \InvalidArgumentException("\$duplicateBehavior was not 'takeFirst', 'takeLast', or 'throw'");
        }

        self::ensureValidKey($keyIndex, '$keyIndex was not a string or integer');
        self::ensureValidKey($valueIndex, '$valueIndex was not a string or integer');

        $result = [];
        foreach ($input as $index => $array) {
            self::ensureIsArray($array, '$arrays was not a multi-dimensional array');

            $key = self::get($array, $keyIndex);
            self::ensureValidKey(
                $key,
                "Value for \$arrays[{$index}][{$keyIndex}] was not a string or integer",
                '\\UnexpectedValueException'
            );

            $value = self::get($array, $valueIndex);
            if (!array_key_exists($key, $result)) {
                $result[$key] = $value;
                continue;
            }

            if ($duplicateBehavior === 'throw') {
                throw new \Exception("Duplicate entry for '{$key}' found.");
            }

            if ($duplicateBehavior === 'takeLast') {
                $result[$key] = $value;
            }
        }

        return $result;
    }