Home  >  Article  >  Backend Development  >  Example of implementation of hexadecimal color random generator function in php

Example of implementation of hexadecimal color random generator function in php

黄舟
黄舟Original
2017-07-24 14:39:251306browse

This article mainly introduces the PHP hexadecimal color random generator function, and analyzes the relevant operating skills of PHP to randomly generate hexadecimal numerical representations based on specific examples. Friends in need can refer to the following

The example in this article describes the PHP hexadecimal color random generator function. Share it with everyone for your reference, the details are as follows:


<?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 $color;
?>

Running results: #8ABED4

The above is the detailed content of Example of implementation of hexadecimal color random generator function in php. For more information, please follow other related articles on the PHP Chinese website!

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