Skip to content
Advertisement

Generating a random hex color code with PHP

I’m working on a project where I need to generate an undefined number of random, hexadecimal color codes…how would I go about building such a function in PHP?

Advertisement

Answer

Get a random number from 0 to 255, then convert it to hex:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement