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.