隨機產生6位數字

<!-- 全部的球放進盒子裡,隨機挑出六個 -->

<?php

$min = 1;

$max = 42;

$total = 6;

// 用PHP二支函式即可做出樂透猜數字

$a_ball = range($min, $max);

$a_box = array_rand($a_ball, $total);

// 顯示

$str = '';

foreach($a_box as $one)   //想像一下;取這盒子內的一顆球,共六次

{ $str .= '<img src="images/' . $a_ball[$one] . '.jpg" width="81" height="81" />';

}

隨機產生6位數字

 

// 排序 (小到大)

sort($a_box);

$str2 = '';

foreach($a_box as $one)

{

    $str2 .= '<img src="images/' . $a_ball[$one] . '.jpg" width="81" height="81" />';

}

隨機產生6位數字

$html = <<< HEREDOC

<html> ....省略一些html

<p>我的樂透猜測</p>

<p>原始順序</p>

<p>{$str}</p>

<p>排序後</p>

<p>{$str2}</p>

....省略一些html

</html>

HEREDOC;

echo $html;

?>

PHP學習_Class6_20201218_t1

By vanessa168

PHP學習_Class6_20201218_t1

隨機產生樂透6位數字

  • 45