Home >Backend Development >PHP Tutorial >PHP随机函数怎么写

PHP随机函数怎么写

WBOY
WBOYOriginal
2016-06-23 13:59:05930browse

<?php$yanse_random=array("#fc9630","#000"):for($i=0;$i<7;$i++){	$left=(550+15*$i);echo'<div class="round_yi'.$i.' jueduidingwei yuandian" style="left:'.$left.'px; top:585px;"></div>';}?>


div设置随机颜色 从$yanse_random 2种颜色随机选 怎么写呢 


回复讨论(解决方案)

rand(min,max)

<?php$yanse_random=array("#fc9630","#000");for($i=0;$i<7;$i++){    $left=(550+15*$i);    $color=$yanse_random[mt_rand(0,1)];	echo'<div class="round_yi'.$i.' jueduidingwei yuandian" style="left:'.$left.'px; top:585px;color:'.$color.'">demo</div>';}?>

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