Shuffle an array while preserving keys.

@param array $values

@return array
518423
private function shuffleAssoc(array $values)
    {
        $keys = array_keys($values);
        shuffle($keys);

        $output = [];
        foreach ($keys as $key) {
            $output[$key] = $values[$key];
        }

        return $output;
    }
609047
protected function detectValues($values): array
    {
        if (!is_array(reset($values))) {
            $values = [$values];
        } else {
            foreach ($values as $key => $value) {
                ksort($value);
                $values[$key] = $value;
            }
        }

        return $values;
    }
203930
public function whereKeys(array $values)
    {
        $repo = $this->getRepo();

        $this->select->whereIn("{$repo->getTable()}.{$repo->getPrimaryKey()}", $values);

        return $this;
    }
904577
public function convertValuesToValueIds($values)
    {
        $tableName   = $this->getSelectSource();
        $idColumn    = $this->getIdColumn();
        $aliasColumn = $this->getAliasColumn();

        if ($idColumn === $aliasColumn) {
            return $values;
        }

        $values = \array_unique(\array_filter($values));
        if (empty($values)) {
            return [];
        }

        return $this->connection->createQueryBuilder()
            ->select($idColumn)
            ->from($tableName)
            ->where($aliasColumn . ' IN (:values)')
            ->setParameter('values', $values, Connection::PARAM_STR_ARRAY)
            ->execute()
            ->fetch(\PDO::FETCH_ASSOC);
    }
766872
public function put($values = [])
	{
		// The usual checks.
		if (empty($values) || !$this->_app->name)
			return [];

		// Work with arrays.
		$values = (array) $values;

		// Does it exists?
		if (!$this->_config)
			$this->getConfig();

		// Perform. Overwrite the values.
		$this->_config = array_merge($this->_config, $values);

		// Save it.
		updateSettings(array('_config'. $this->_app->name => json_encode($this->_config)));

		// Done!
		return $this->_config;
	}
25319
private function sortValues($values)
    {
        if (!($this->orderField && \is_array($this->{$this->orderField}))) {
            return $values;
        }
        /** @var array $orderValues */
        $orderValues = $this->{$this->orderField};
        $result      = [];
        foreach ($orderValues as $i) {
            if (isset($values[$i])) {
                $result[$i] = $values[$i];
                unset($values[$i]);
            }
        }
        if (!empty($values)) {
            foreach ($values as $k => $v) {
                $result[$k] = $v;
            }
        }
        return $result;
    }
290694
public function stripVOID($Values)
    {
        if (!is_array($Values)) {
            return [];
        }
        $Result = [];
        foreach ($Values as $Value) {
            if ($Value != VOID) {
                $Result[] = $Value;
            }
        }
        return $Result;
    }
1067242
private static function getValues(array $values)
    {
        $bag = MutableBag::from($values);
        foreach ($bag as $k => $v) {
            /** @var Bag $v */
            if (is_array($v) && !is_callable($v)) {
                $bag[$k] = Bag::from($v)
                    ->call(function (array $a) {
                        return [Json::dump($a)];
                    })
                    ->join(' ')
                ;
            } elseif (is_string($v) || (is_object($v) && method_exists($v, '__toString'))) {
                $bag[$k] = (string) $v;
            } else {
                $bag->remove($k);
            }
        }

        return $bag->immutable();
    }
1302122
public function insert(array $values)
    {
        $n_inserted = 0;

        $resets = [];

        foreach ($values as $key => $value) {
            if (is_array($value)) {
                $n_inserted += $this->insertOne($value);
            } else {
                $resets[$key] = $value;
            }

            unset($values[$key]);
        }

        if (!empty($resets)) {
            $n_inserted += $this->insertOne($resets);
        }

        return $n_inserted;
    }
476566
protected function setForeignKeys(array $values)
    {
        foreach ($values as $key => &$value) {
            if ($this->endsWith($key, '_id') && !is_int($value)) {
                list($table, $label) = $this->parseRecordLabel($value);
                $value = $this->generateKey($label, $table);
            }
        }

        return $values;
    }
177155
public function unshift ($values = [])
	{
		if (!is_an_array($values) || $values instanceof \Sauce\SObject) {
			$values = [ $values ];
		}

		$values = V($values);
		$storage = $this->storage;

		for ($i = ($values->count() - 1); $i >= 0; $i--) {
			array_unshift($storage, $values[$i]);
		}

		$this->storage = $storage;

		return null;
	}
1094611
public function unshift(...$values)
    {
        $this->forceCollection();
        $values = array_map([$this, 'unbox'], $values);
        array_unshift($this->data, ...$values);

        return $this;
    }
908524
public static function flatten(array $values)
    {
        $results = [];

        array_walk_recursive(
            $values,
            function($value) use (&$results) {
                $results[] = $value;
            }
        );

        return $results;
    }
854727
public static function fillArrayKeys($keys, $value)
    {
        $arrayKeys = is_array($keys) ? $keys : explode('.', $keys);

        $array = array();
        foreach (array_reverse($arrayKeys) as $i => $key) {
            $array = array(
                $key => ($i == 0) ? $value : $array,
            );
        }

        return $array;
    }
1242280
public function addValues(array $values)
    {
        // Check if this is a multi-dimensional array
        $isMultiDimensional = 0 == count($values) || (isset($values[0]) && is_array($values[0]));

        if ($isMultiDimensional) {
            $this->insertRows = array_merge($this->insertRows, $values);
        } else {
            // If a single row is provided then it is added
            // to the last row, or a new row if there are none.
            // This is done to maintain BC
            if (count($this->insertRows) > 0) {
                $k = count($this->insertRows) - 1;
                $this->insertRows[$k] = array_replace($this->insertRows[$k], $values);
            } else {
                $this->insertRows = [$values];
            }
        }

        return $this;
    }
1217795
public function convert(array $values)
    {
        $tmp = [];

        foreach ($values as $key => $value) {
            $tmp[strtolower($key)] = $value;
        }

        return $this->hydrate($tmp);
    }
1061520
protected function putManyForever(array $values)
    {
        $result = true;

        foreach ($values as $key => $value) {
            if (! $this->forever($key, $value)) {
                $result = false;
            }
        }

        return $result;
    }