<?php
include("include/function.php");
// 1. 取得亂數
$handn = rand(1,3);
// echo $handn;
// 2. 設定檔名
if ( $handn == 1 ){
$hand ="scissors.png";
} elseif ( $handn == 2 ){
$hand ="rock.png";
} elseif ( $handn == 3 ){
$hand ="paper.png";
}
// 3. 到正確的地方去 echo 檔名即可
// echo $hand;
?>
body的部分:
<div class="rand">
<img src="images/<?php echo"$hand"; ?>" />
</div>