function
shuffle_assoc(
$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
;
$random
=
array
();
foreach
(
$keys
as
$key
)
$random
[
$key
] = shuffle_assoc(
$list
[
$key
]);
return
$random
;
?> 以下函数也是出自php手册,可以打乱多维数组:
$ary_keys
=
array_keys
(
$array
);
$ary_values
=
array_values
(
$array
);
shuffle(
$ary_values
);
foreach
(
$ary_keys
as
$key
=>
$value
) {
if
(
is_array
(
$ary_values
[
$key
]) AND
$ary_values
[
$key
] != NULL) {
$ary_values
[
$key
] = rec_assoc_shuffle(
$ary_values
[
$key
]);
$new
[
$value
] =
$ary_values
[
$key
];
return
$new
;
用知识的力量武装,把生活的绚烂点亮!