PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Lets say i have 3 textboxes in page A. Before i submit this page, i want to check all the textboxes' value to make sure all the values are different. If there are only 3 textboxes, i can code it like this:
One thing you have to be careful about is to not check each one against every single one, as that would give you an exponential growth, meaning that with 100 boxes you would do 10000 tests.
A very simple solution is to store each of the values in an array, with the value as the key, and just anything as the value. Then checking the length of the array against the number of checkboxes. This ensures that it is has a linear behaviour at most times. (Also, note that if you name the checkboxes val[0] val[1] etc, you could just flip the val-array and you have your array.
Syranide wrote:One thing you have to be careful about is to not check each one against every single one, as that would give you an exponential growth, meaning that with 100 boxes you would do 10000 tests.
A very simple solution is to store each of the values in an array, with the value as the key, and just anything as the value. Then checking the length of the array against the number of checkboxes. This ensures that it is has a linear behaviour at most times. (Also, note that if you name the checkboxes val[0] val[1] etc, you could just flip the val-array and you have your array.