PHP代码 - 获取随机颜色代码

方法一:完全随机颜色

<?php
function randColor(){
    $colors = array();
    for($i = 0;$i<6;$i++){
        $colors[] = dechex(rand(0,15));
    }
    return implode('',$colors);
}
?>
使用颜色方法:
<?php echo '<span style="color: #'.randColor().'">随机颜色:#'.randColor().'</span>';?>
方法二:随机挑选数组里的颜色
<?php
function randColor(){
    $colors=array('5CB85C','428BCA','FF6600','D9534F','B37333','00ABA9');
    $show_color = array_rand($colors, 1);
    return $colors[$show_color];
}
?>
颜色使用方法同上:
<?php echo '<span style="color: #'.randColor().'">随机颜色:#'.randColor().'</span>';?>

转载请注明出处 AE博客|墨渊 » PHP代码 - 获取随机颜色代码

相关推荐

发表评论

路人甲

网友评论(2)

我喜欢用js。◕‿◕。
诗梦 6年前 (2018-07-16) 回复
@诗梦:萝卜白菜,你爱青菜
墨渊 6年前 (2018-07-17) 回复