php 在PHP中生成随机颜色

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在PHP中生成随机颜色相关的知识,希望对你有一定的参考价值。

<?php

/*
 * Get Random Color
 */
if (! function_exists('random_color')) {
    function random_color()
    {
        return sprintf('#%06X', mt_rand(0, 0xFFFFFF));
    }
}

/*
 * Get Random Colors
 */
if (! function_exists('random_colors')) {
    function random_colors($number_of_colors)
    {
        $colors = [];
        for ($i=0; $i < $number_of_colors; $i++) { 
            $colors[] = random_color();
        }
        return $colors;
    }
}

以上是关于php 在PHP中生成随机颜色的主要内容,如果未能解决你的问题,请参考以下文章