php怎么生成不重复颜色

来自:互联网
时间:2021-09-25
阅读:

php怎么生成不重复颜色?

php生成多个随机不重复颜色代码

代码如下:

<?php
function randColor($num){
//color value limits 0-16777215;
$prehash='#'; //using string '#' before the color value;
$rsArr= array();
for($i=0;$i<$num;$i++){
$color=rand(0,16777215);
$rsArr[$i]=$prehash.dechex($color);
}
return $rsArr;
}
print_r(randColor(20));
?>

把生成随机数字的函数放到循环里就行。

返回顶部
顶部