<?php $min=1; $max=100; $password=rand(1,$max); echo "密碼 : ".$password."<br>"; $index=1; while(true){ echo "第".$index."次 : "; $guess=rand($min+1, $max-1); echo $guess; if($guess==$password){ echo " <==bingo"; break; } else if ($guess<$password) $min=$guess; else $max=$guess; echo " 介於 $min ~ $max 之間"; $index++; echo "<br>"; } ?>