<?php
header("Content-type:text/html;charset=utf-8");
$arr =array("香蕉","苹果","梨子","橙子","橘子","榴莲");
var_dump($arr);
if (!empty($arr)) {
$key =array_keys($arr);
shuffle($key);
foreach ($key as $value) {
$arr2[$value] =$arr[$value];
}
$arr =$arr2;
}
echo "随机打乱数组:";
var_dump($arr);
?>
/**
- 打乱维数组排序-并保持索引
- @param array $list
- @return array
*/
if (!function_exists('shuffleAssoc')) {
function shuffleAssoc(lists)){
return keys = array_keys(keys);
keys as value){
k] = value];
}
}
return $result;
}
}
}
网友评论