不言不语

您现在的位置是: 首页 >  PHP

PHP

PHP生成随机颜色代码

2022-06-06PHP
PHP2种方法生成随机颜色代码

方法一:完全随机颜色

<?php
function randColor(){
    $colors = array();
    for($i = 0;$i<6;$i++){
        $colors[] = dechex(rand(0,15));
    }
    return implode('',$colors);
}
?>

方法二:随机挑选数组里的颜色

<?php
function randColor(){
    $colors=array('5CB85C','428BCA','FF6600','D9534F','B37333','00ABA9');
    $show_color = array_rand($colors, 1);
    return $colors[$show_color];
}
?>

 

文章评论