If they don’t have the exact amount of points, they can’t get such voucher.
For example: User has 249 points, he can only get a $20 voucher until he gets 1 more point… it will then display he can get a $20 voucher with 100 points, and 149 points remaining.
Suppose you have 249 points. $amt now starts at 0.
It looks if you have 100 points or more, you do, so $amt=20.
Now it looks if you have 250 points or more, you don’t, so the foreach loop breaks, and you have $amt=20, which is what you want.
Note that for this approach to work the keys in $rewards need to be sorted ascending. For example, the following doesn’t work:
Because the loop will start to see if you have 500 points or more, you don’t, so you’re stuck with $amt = 0
BTW. I’m hoping you will implement the points in more secure way than just $_GET[‘pts’] ? This way I can just go to your website and change ?pts=some-value to ?pts=1000000 and I have 1 million points!
You can get 1 vouchers for 200$
You can get 1 vouchers for 100$
You can get 1 vouchers for 50$
You can get 1 vouchers for 20$
You have 1 points remaining