Php generates a summary of random color methods, and php generates a summary. Php generates a summary of the random color method. php generates a summary method. Method 1: generate a random color value (for example, FF00FF ). color. the php copy code is as follows: functionrandom_color () {mt_srand (doubl php generates a random color method summary, php generates a summary
Method 1:
Generate a random color value (for example, FF00FF ).
Color. php
The code is as follows:
Function random_color (){
Mt_srand (double) microtime () * 1000000 );
$ C = '';
While (strlen ($ c) <6 ){
$ C. = sprintf ("% 02X", mt_rand (0,255 ));
}
Return $ c;
}
Method 2:
The code is as follows:
Function randrgb ()
{
$ Str = '0123456789abcdef ';
$ Estr = '#';
$ Len = strlen ($ str );
For ($ I = 1; $ I <= 6; $ I ++)
{
$ Num = rand (0, $ len-1 );
$ Estr = $ estr. $ str [$ num];
}
Return $ estr;
}
Method 3:
The code is as follows:
Function randColor (){
$ Colors = array ();
For ($ I = 0; $ I <6; $ I ++ ){
$ Colors [] = dechex (rand (0, 15 ));
}
Return implode ('', $ colors );
}
The usage is as follows:
<? Php echo 'random color: # '. randColor (). '';?>
Method 1: randomly generate a color value (for example, FF00FF). the color. php code is as follows: function random_color () {mt_srand (doubl...