PHP are three ways to generate a random number of color

The first

<?php
$red = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33);
$blue = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
for ($i=0;$i<6;$i++){
$index = rand(0,32-$i);
$redBall[]= $red[$index];
unset($red[$index]);
for($k=$index;$k<count($red)-1;$k++){
   $red[$k]=$red[$k+1];
}
}
asort($redBall);
?>
<div style="background-color:red;color:white;width:160px;float:left;text-align:center;">
<?php
foreach($redBall as $v){
echo $v." ";
}
?>
</div>
<div style="background-color:blue;color:white;width:40px;float:left;text-align:center">
<?php
echo $blue[rand(0,15)];
?>
</div>

The second

<?php
echo "<br>";
echo "<p>";
$red1=range(1,33);
$blue1=mt_rand(1,6);
$sc1=array_rand($red1,6);
?>
<div style="background-color:red;color:white;width:160px;float:left;text-align:center;">
<?php
foreach($sc1 as $v){
echo "$v ";
}
?>
</div>
<div style="background-color:blue;color:white;width:40px;float:left;text-align:center">
<?php
echo "$blue1";
?>
</div> 

The third

? < PHP
     $ ARR = Array ();
     $ Special = Array ();
     // I -32 bit number 
    for ( $ I =. 1; $ I <= 32; $ I ++ ) {
         $ ARR [ $ I ] = I $ ; 
    } 
    // 1-15 special numbers 
    for ( $ I =. 1; $ I <= 15; $ I ++ ) { 
         $ special [ $ I ] = $ I ; 
    } 
    // randomly array 
    $ arr2 is = array_rand($arr,6);
    $arr3 = array_rand($special,1);
    
    $arr2[] = $arr3;

    $str = "<div style='font-size:16px;padding-top:10px;text-align:center'>";
    foreach($arr2 as $v){
        $str .= "<span style='color:red;font-size:25px'>$v---</span>";
    }
    $str .='</div>';
    
    echo $str;

?>

 

Guess you like

Origin www.cnblogs.com/shenjingwa/p/11864471.html