从多个选项中选择十六进制颜色代码

时间:2010-08-12 01:54:37

标签: php colors random

尝试使其正常运行,随机选择3种颜色中的1种。 兰特只能产生数字吗?或系列中的数字/字母。

<div onclick="location.href='<?php the_permalink() ?>';"
style="cursor:pointer;background:#<?php echo rand (DDCA73, A0AA47, ADBAE1)?>;" 
class="post bg thickbox" id="thickbox post-<?php the_ID(); ?>">

1 个答案:

答案 0 :(得分:1)

** rand或mt_rand使数字随机化而不是字符串。创建一个数组,然后随机选择它的键选择。

<?php
    function random_color(){                   
            $colors_avail = array("DDCA73","A0AA47","ADBAE1");      
            $colors_count = count($colors_avail)-1; 
            $color_wheel = $colors_avail[mt_rand(0,$colors_count)];        
            echo $color_wheel;
     }
?>

<div onclick="location.href='<?php the_permalink() ?>';"
style="cursor:pointer;background:#<?php random_color(); ?>;" 
class="post bg thickbox" id="thickbox post-<?php the_ID(); ?>">
相关问题