-鍵盤輸入四個學生的學號 姓名 語文 數學 英文資訊 ,計算出每位學生的平均成績,輸出
- 學生的資料包括 學號 姓名語文 數學 英文 平均成績 ,4個學生的資訊存數組中。
<code><span>$student</span>=<span>array</span>(); <span>$student</span>=<span>array</span>( <span>array</span>(<span>'name'</span> =><span>'a'</span> ,<span>'chinese'</span>=><span>80</span>,<span>'math'</span>=><span>80</span>,<span>'english'</span>=><span>70</span>,<span>'avg'</span>=><span>''</span> ), <span>array</span>(<span>'name'</span> =><span>'b'</span> ,<span>'chinese'</span>=><span>70</span>,<span>'math'</span>=><span>70</span>,<span>'english'</span>=><span>90</span>,<span>'avg'</span>=><span>''</span> ), <span>array</span>(<span>'name'</span> =><span>'c'</span> ,<span>'chinese'</span>=><span>60</span>,<span>'math'</span>=><span>90</span>,<span>'english'</span>=><span>80</span>,<span>'avg'</span>=><span>''</span> ), <span>array</span>(<span>'name'</span> =><span>'d'</span> ,<span>'chinese'</span>=><span>50</span>,<span>'math'</span>=><span>60</span>,<span>'english'</span>=><span>60</span>,<span>'avg'</span>=><span>''</span> ), ); <span>//计算平均成绩</span><span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span><count(<span>$student</span>);<span>$i</span>++){ <span>$total</span>=<span>$student</span>[<span>$i</span>][<span>'chinese'</span>]+<span>$student</span>[<span>$i</span>][<span>'english'</span>]; <span>$total</span>+=<span>$student</span>[<span>$i</span>][<span>'math'</span>]; <span>$student</span>[<span>$i</span>][<span>'avg'</span>]=<span>$total</span>/<span>3</span>; } <span>//输出</span><span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span><count(<span>$student</span>);<span>$i</span>++){ <span>echo</span><span>'name'</span>.<span>'=>'.<span>$student</span>[<span>$i</span>][<span>'name'</span>].<span>'chinese'</span>.<span>'=>'</span>.<span>$student</span>[<span>$i</span>][<span>'chinese'</span>].<span>'math'</span>.<span>'=>'</span>.<span>$student</span>[<span>$i</span>][<span>'math'</span>].<span>'english'</span>.<span>'=>'</span>.<span>$student</span>[<span>$i</span>][<span>'english'</span>].<span>'avg'</span>.<span>'=>'</span>.<span>$student</span>[<span>$i</span>][<span>'avg'</span>].<span>'<br>'</span>; } </code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介紹了 PHP之鍵盤輸入四個學生的學號 姓名 語文 數學 英語資訊 ,計算出每個學生的平均成績,輸出,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。