DBookatay Posted January 28, 2013 Share Posted January 28, 2013 For some reason this array keeps repeating the 1st line onto the 2nd line and the 1st and 2nd line onto the 3rd line, and so on and so on. unset ($grade); $grade = array(); foreach ($row as $grade => $value) { if (substr($grade, 0,1)== "y") { if ($grade == "y1") {if ($value == "x") {$grades[] = "1";}} if ($grade == "y2") {if ($value == "x") {$grades[] = "2";}} if ($grade == "y3") {if ($value == "x") {$grades[] = "3";}} if ($grade == "y4") {if ($value == "x") {$grades[] = "4";}} if ($grade == "y5") {if ($value == "x") {$grades[] = "5";}} if ($grade == "y6") {if ($value == "x") {$grades[] = "6";}} if ($grade == "y7") {if ($value == "x") {$grades[] = "7";}} } } $grades_string = implode(", ", $grades); The dB rows are titled y1, y2 etc. I can show someone a link with the example of what I mean the error is if need be. Quote Link to comment https://forums.phpfreaks.com/topic/273712-repeating-array-not-supposed-to/ Share on other sites More sharing options...
DBookatay Posted January 28, 2013 Author Share Posted January 28, 2013 For some reason this array keeps repeating the 1st line onto the 2nd line and the 1st and 2nd line onto the 3rd line, and so on and so on. unset ($grade); $grade = array(); foreach ($row as $grade => $value) { if (substr($grade, 0,1)== "y") { if ($grade == "y1") {if ($value == "x") {$grades[] = "1";}} if ($grade == "y2") {if ($value == "x") {$grades[] = "2";}} if ($grade == "y3") {if ($value == "x") {$grades[] = "3";}} if ($grade == "y4") {if ($value == "x") {$grades[] = "4";}} if ($grade == "y5") {if ($value == "x") {$grades[] = "5";}} if ($grade == "y6") {if ($value == "x") {$grades[] = "6";}} if ($grade == "y7") {if ($value == "x") {$grades[] = "7";}} } } $grades_string = implode(", ", $grades); The dB rows are titled y1, y2 etc. I can show someone a link with the example of what I mean the error is if need be. Rewrote it, problem was it should of been unset ($grade); $grades = array(); unset ($grade); $grades = array(); foreach ($row as $grade => $value) { if (substr($grade, 0,1)== "y" && $value == "x") { if ($grade == "y1") {$grades[] = "1";} if ($grade == "y2") {$grades[] = "2";} if ($grade == "y3") {$grades[] = "3";} if ($grade == "y4") {$grades[] = "4";} if ($grade == "y5") {$grades[] = "5";} if ($grade == "y6") {$grades[] = "6";} if ($grade == "y7") {$grades[] = "7";} } } $grades_string = implode(", ", $grades); Quote Link to comment https://forums.phpfreaks.com/topic/273712-repeating-array-not-supposed-to/#findComment-1408634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.