php 生成随机颜色
1
function rand_color(){ $str='0123456789ABCDEF'; $estr='#'; $len=strlen($str); for($i=1;$i<=6;$i++) { $num=rand(0,$len-1); $estr=$estr.$str[$num]; } return $estr; }2
function mbw_color(){ $s = '#'; $c = array('26a2b6','0085c6','51A351','f0bf4a','ff5c00','bd362f','b9298f','c9c','00b5ad','ff8edf','f00','076FBD','449f04','EE6E33','8F36B1','6cc','6c9','f96'); shuffle($c); foreach($c as $v) { return $s.= $v; } } //自定义固定的颜色在随机3
<?php $mbw_color = array('danger','warning','primary','secondary','success')?> //数组 <a href="#" class="<?php echo $mbw_color[array_rand($mbw_color)]?>">标签</a> <a href="#" class="<?php echo $mbw_color[array_rand($mbw_color)]?>">tag</a> css .danger{color:#adc} .warning{color:#acc} .primary{color:#add} .secondary{color:#acc} .success{color:#aaa}