Home > Backend Development > PHP Tutorial > PHP random color generator

PHP random color generator

WBOY
Release: 2016-07-25 08:46:02
Original
1131 people have browsed it
  1. function randomColor() {
  2. $str = '#';
  3. for($i = 0 ; $i < 6 ; $i++) {
  4. $randNum = rand(0 , 15);
  5. switch ($randNum) {
  6. case 10: $randNum = 'A'; break;
  7. case 11: $randNum = 'B'; break;
  8. case 12: $randNum = 'C'; break;
  9. case 13: $randNum = 'D'; break;
  10. case 14: $randNum = 'E'; break;
  11. case 15: $randNum = 'F'; break;
  12. }
  13. $str .= $randNum;
  14. }
  15. return $str;
  16. }
  17. $color = randomColor();
复制代码

PHP


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template