Skip to content

Instantly share code, notes, and snippets.

@Stanton
Created December 14, 2011 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stanton/1476863 to your computer and use it in GitHub Desktop.
Save Stanton/1476863 to your computer and use it in GitHub Desktop.
Validation for James
<?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