Skip to content
Advertisement

same results for php if inside foreach

My problem is that as soon as my php variable was used for the first time, the same value shows up in every loop, though it is uncorrect:

JavaScript

As soon as I have a correct result for $goals_match > 4 the 1 shows up correctly. But in my next results no matter if wrong or right, the 1 appears again and again.

I have checked several posts in here, but have not found any tips to solve this problem. Would be great if you could help me here!

Thank you very much!

Advertisement

Answer

This is happening because you’re not resetting or re-initialising the $goals_p4 variable once it has been used, as such it is keeping the value.

One way of fixing this would be the following, but you don’t state what a default value for $goals_p4 should be, or if the value should be stored somewhere:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement