Home >Backend Development >PHP Tutorial >Example of implementation of hexadecimal color random generator function in php
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 = '#'; for($i = 0 ; $i < 6 ; $i++) { $randNum = rand(0 , 15); switch ($randNum) { case 10: $randNum = 'A'; break; case 11: $randNum = 'B'; break; case 12: $randNum = 'C'; break; case 13: $randNum = 'D'; break; case 14: $randNum = 'E'; break; case 15: $randNum = 'F'; 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!