How can I cycle through hex color codes in PHP?

前端 未结 9 2244
野的像风
野的像风 2021-01-06 06:08

I want an array where each field in the array contains a color code

array(0 => \'#4CFF00\', 1 => \'#FFE97F\')

And I want this to go t

9条回答
  •  感动是毒
    2021-01-06 06:26

    I stumbled upon this question - and surprisingly I could not find an actual solution for this on the web (I did not try hard). Performance is besides the point here - this is not what you would want to do - this is just an exercise - but if you actually wanted to iterate over all hex colors - here is how you could do it:

    for($i = 0; $i <= 16777215; $i++) {
        echo sprintf('%06s', dechex($i));
    }
    

    Of course this question is old and answered, but thought I would share this anyway.

提交回复
热议问题