-键盘输入四个学生的学号 姓名 语文 数学 英语信息 ,计算出每个学生的平均成绩,输出
- 学生的信息包括 学号 姓名语文 数学 英语 平均成绩 ,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>$student);<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>$student);<span>$i</span>++){ <span>echo</span><span>'name'</span>.<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>; } </count></count></code>
以上就介绍了 PHP之键盘输入四个学生的学号 姓名 语文 数学 英语信息 ,计算出每个学生的平均成绩,输出,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。