Home  >  Article  >  php教程  >  随机颜色生成器

随机颜色生成器

PHP中文网
PHP中文网Original
2016-05-25 17:13:391449browse

随机颜色生成器

<?php
function randomColor() {
    $str = &#39;#&#39;;
    for($i = 0 ; $i < 6 ; $i++) {
        $randNum = rand(0 , 15);
        switch ($randNum) {
            case 10: $randNum = &#39;A&#39;; break;
            case 11: $randNum = &#39;B&#39;; break;
            case 12: $randNum = &#39;C&#39;; break;
            case 13: $randNum = &#39;D&#39;; break;
            case 14: $randNum = &#39;E&#39;; break;
            case 15: $randNum = &#39;F&#39;; break;
        }
        $str .= $randNum;
    }
    return $str;
}
$color = randomColor();
echo &#39;Random color: &#39;.$color.&#39;&#39;;
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn