a::shuffle PHP Method

shuffle() static public method

Shuffles an array and keeps the keys
static public shuffle ( array $array ) : array
$array array The source array
return array The shuffled result array
    static function shuffle($array)
    {
        $keys = array_keys($array);
        shuffle($keys);
        return array_merge(array_flip($keys), $array);
    }

Usage Example

Example #1
0
 public function testShuffle()
 {
     $users = $this->users;
     $users = a::shuffle($users);
     // the only testable thing is that keys still exist
     $this->assertTrue(isset($users['userA']));
 }
All Usage Examples Of a::shuffle