Home > Backend Development > PHP Tutorial > Use the PHP keyboard to input the student number, name, Chinese, mathematics, and English information of four students, calculate the average score of each student, and output

Use the PHP keyboard to input the student number, name, Chinese, mathematics, and English information of four students, calculate the average score of each student, and output

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-28 08:26:00
Original
2630 people have browsed it

-Enter the student number, name, Chinese, mathematics, and English information of four students on the keyboard, calculate the average score of each student, and output
- The student's information includes student number, name, Chinese, mathematics, English, average grade, and the information of 4 students is stored in the array.

<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>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the PHP keyboard to input the student number, name, Chinese, mathematics, and English information of four students, calculates the average score of each student, and outputs it, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template