Created
December 14, 2011 14:46
-
-
Save Stanton/1476863 to your computer and use it in GitHub Desktop.
Validation for James
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// set up a stack | |
$options = array(); | |
/* our list of values to ignore (the ones that are permitted to be duplicates) | |
(made into an array so that you can easily add other options to be ignored, | |
without having to modify the other rules) */ | |
$exceptions = array('10'); | |
// rule out empty values | |
if (!empty($option1) && !in_array($exceptions, $option1)) { | |
array_push($options, $option1); // push the value to the stack | |
} | |
if (!empty($option2) && !in_array($exceptions, $option2)) { | |
array_push($options, $option2); | |
} | |
/* | |
... repeat for each $option | |
$options should now look like this: | |
array ( | |
[0] => value1 | |
[1] => value2 | |
[2] => value3 | |
[3] => value4 | |
[4] => value5 | |
) | |
*/ | |
/* Check the size of the stack against the size of the stack with duplicates | |
removed, if it's smaller, we know there were duplicates, if it's the same | |
size, we're fine */ | |
if (sizeof($options) < sizeof(array_unique($options))) { | |
$errorMessage = 'Error - you cannot pick the same reward more than once | |
(except pension contribution).'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment