Ec (2); set the font size and color of the tag according to the click rate of the tag. This program does not consider program performance and function encapsulation... The code for expressing this algorithm is as follows: & nbsp; & lt ;? Php & nbsp; function & nbsp; showTag ($ cur47, $ tag & quot; beauty & quot;) {& nbsp; & nbsp; & nbs script ec (2); script
Set the font size and color of a tag Based on the click rate of the tag.
This program does not consider program performance and function encapsulation... Just want to express this algorithm
The Code is as follows:
Function showTag ($ cur = 47, $ tag = "Beauty and the Beast "){
$ MaxSize = 300; $ minSize = 30; // maxSize indicates the maximum label font size, and minSize indicates the minimum label size.
$ Max = 100; $ min = 8; // max indicates the maximum number of tag clicks. min indicates the minimum number of clicks. cur indicates the current tag clicks.
$ TagColor = $ tagSize = $ minSize; # tagColor indicates the final color of the tag, and tagsize indicates the final font size of the tag.
$ TagSize = @ (float) ($ cur-$ min)/($ max-$ min) * ($ maxSize-$ minSize );
$ Colors = array ("0.2" => "#333333", "0.4" => "# 0033CC", "0.6" => "#660099 ", "0.8" => "#00 FFFF", "1" => "# FF0000 ");
// Color is an array of colors, which can be characters in length, for example, color1 between 0-0.2.
$ Colorkeys = array_keys ($ colors );
$ Select = (float) ($ cur-$ min)/($ max-$ min );
$ Len = count ($ colorkeys );
$ I = 0; $ j = $ len-1;
While ($ I <$ j) {// Binary Search
$ Index = ($ I + $ j)/2;
If ($ select >=( float) $ colorkeys [$ index] & $ select <(float) $ colorkeys [$ index + 1]) break;
Elseif ($ select <(float) $ colorkeys [$ index]) $ j --;
Elseif ($ select> (float) $ colorkeys [$ index]) $ I ++;
Elseif ($ select = (float) $ colorkeys [$ index + 1]) break;
Else break;
}
$ TagColor = $ colors [$ colorkeys {($ I + $ j)/2}];
Echo "$ tag ";
}
ShowTag (90); showTag (66, "stockholders"); showTag (50, "My hobbies"); showTag (100, "MM ");
?>