Incorrect foreach output value in PHP

Source: Internet
Author: User
In PHP, the foreach output value is incorrectly obtained into a score on the page a.html, or the student ID is passed to another php file B. PHP to query the corresponding student ID or score.
Pass stuNum, grade, and flag from a webpage to the file
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 "none of this object ";} else if ($ searchFlag = 1) {echo "student ID is ". "$ num ". "The student score is :". "$ result";} else {echo "Score ". "$ num ". "Student ID:"; var_dump ($ result); foreach ($ result as $ key => $ vaule) {echo "$ key ". "" ;}}?>

When you search for the student ID through the score, enter 45, there are two corresponding student IDs, and save them in an array. the var_dump command is correct, array ([0] => 1 [1] => 5)
However, through the foreach traversal below, the $ key value is 0, 1, but $ value is indeed 68.
Ask for advice.


Reply to discussion (solution)

Is it true that if ($ num = $ key) in the 11 rows?
OnlyNone

In addition, your student ID and score are all taken from $ grade = array (, 45 );
How can we tell who is it?

Sorry, I didn't make it clear. I just used the default student ID 0-9, which is equivalent to $ key equivalent to student ID. $ Num is passed from other pages, indicating the student ID to be queried. the corresponding $ value is output as long as it matches the $ key. NotNone

...... Understand. $ 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.