src/Component/Json.php
/**
     * Shuffles values of a countable.
     *
     * @param ?string|int $index
     * @return self
     * @see https://stackoverflow.com/a/32035692/4215651 Thanks to this.
     */
Shuffles values of a countable.
Shuffles values of a countable .
public function shuffle($index = null): self
    {
        $this->do(function (array &$array) {
            $arrayKeys = array_keys($array);
            $shuffledArray = [];
            $arrayIndexLength = count($array) - 1;
            while (count($shuffledArray) <= $arrayIndexLength) {
                $randomKey = $arrayKeys[($this->randomizationFunction)(0, $arrayIndexLength)];
                $shuffledArray[$randomKey] = $array[$randomKey];
            }
            $array = $shuffledArray;
        }, $index, true);
        return $this;
    }
public function shuffle ( $ index = null ) : self { $ this -> do ( function ( array & $ array ) { $ arrayKeys = array_keys ( $ array ) ; $ shuffledArray = [ ] ; $ arrayIndexLength = count ( $ array ) - 1 ; while ( count ( $ shuffledArray ) <= $ arrayIndexLength ) { $ randomKey = $ arrayKeys [ ( $ this -> randomizationFunction ) ( 0 , $ arrayIndexLength ) ] ; $ shuffledArray [ $ randomKey ] = $ array [ $ randomKey ] ; } $ array = $ shuffledArray ; } , $ index , true ) ; return $ this ; }
Shuffles values of a countable.
Shuffles values of a countable .