Incorrect foreach output value in PHP

Source: Internet
Author: User
Need to achieve on a page a.html input scores or school numbers passed to another PHP file b.php query the corresponding number or score.
From a webpage to the file pass student number Stunum, score grade, hide form flag flag
The b.php code is as follows:
 
  $value) {if ($num = = $key) {$searchFlag =1; $result = $value;}}} else{$num =$_request[' Grade '];foreach ($grade as $key = = $value) {if ($num = = $value) {$searchFlag =2; $result []= $key;}}} if ($searchFlag ==0) {echo "no this object";} else if ($searchFlag ==1) {echo ' number is '. ' $num "." Student scores are: "." $result ";} Else{echo "score is". " $num "." The student number is: "; Var_dump ($result); foreach ($result as $key = + $vaule) {echo" $key "." ";}}? >

Through the score to find the study number, enter 45, there is a corresponding two number, with an array to save, through the var_dump display is correct, array ([0] = 1 [1] + 5)
But with the following foreach traversal, the $key value is 0,1, but the $value is 68, 68.
For advice


Reply to discussion (solution)

11 lines of if ($num = = $key) is that right?
can only be obtained without this object

In addition your study number, results are taken from $grade =array (23,45,65,87,95,45,32,84,54,68);
How to distinguish who is who?

Sorry, not clear, study number I am directly using the default of 0-9, equivalent to $key equivalent to the school number. $num is transmitted from other pages, indicating the number of queries, as long as the match with $key will be the corresponding $value output. There is no such object

。。。。。。 You know, $value variable name is wrong.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.