You are here

function MultifieldTableTest::shuffleAssoc in Multifield table 7

Shuffles an array preserving it keys.

Parameters

array $list: Array to shuffle

Return value

array The assoc shuffled array

1 call to MultifieldTableTest::shuffleAssoc()
MultifieldTableTest::testMultifieldTableBasic in ./multifield_table.test
Performs the basic tests.

File

./multifield_table.test, line 109

Class

MultifieldTableTest

Code

function shuffleAssoc($list) {
  if (!is_array($list)) {
    return $list;
  }
  $keys = array_keys($list);
  shuffle($keys);
  $random = array();
  foreach ($keys as $key) {
    $random[$key] = $list[$key];
  }
  return $random;
}