看板 PHP 關於我們 聯絡資訊
※ 引述《HarryWen (Harry)》之銘言: : http://i.imgur.com/t1fyTrC.jpg
: http://i.imgur.com/NdFwdI6.jpg
: http://i.imgur.com/P77pKq2.jpg
: 請各位幫幫忙 /*練習6*/ $array = array(); $max = 0; for($i=0;$i<10;$i++){ //(1) $rand = rand(1,50); if($max < $rand) $max = $rand; array_push($array,$rand); //(2) echo $rand;//(2) } print_r($array);//(3) echo $max;//(4) /*練習6 end*/ /*練習7*/ $array = array_fill(1,6,0); for($i=0;$i<100;$i++){ //(1) $rand = rand(1,6); $array[$rand]++;//(2) } foreach($array as $key => $value){//(3) echo "出現 {$key}點 的機率為 {probability($value)}".PHP_EOL; } function probability($count){//(3) return $count/100; } /*練習7 end*/ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.161.65.185 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1447041834.A.41F.html ※ 編輯: jhunkyoiori (218.161.65.185), 11/09/2015 12:08:01 ※ 編輯: jhunkyoiori (218.161.65.185), 11/09/2015 12:12:19 ※ 編輯: jhunkyoiori (218.161.65.185), 11/09/2015 12:44:20