if (is_array($field_value)) {
reset($field_value);
while (list($key, $value) = each ($field_value)) {
if (htmlentities(stripslashes($value)) == $hyperlink) {
$this->showOptionDefault($hyperlink, $arrRecordSet['Element_Content']);
} else {
$this->showOption($hyperlink, $arrRecordSet['Element_Content']);
}
}
} else if ($field_value == $hyperlink) {
$this->showOptionDefault($hyperlink, $arrRecordSet['Element_Content']);
} else {
$this->showOption($hyperlink, $arrRecordSet['Element_Content']);
}
$field_value holds the array from a select multiple name=array[] in an HTML form. The while loop executes for each $value the user selected (each option in the select multiple on the HTML form the user selected).
Problem:
Lets say $arrRecordSet['Element_Content'] is equal to "Paul"
First $value is equal to "George"
Second $value is equal to "Peter"
If neither "George" nor "Peter" was selected, then...
$this->showOption($hyperlink, $arrRecordSet['Element_Content']);
...executes twice and I end up with two "Paul"s on the result page which contains the same select multiple box.
What I want this code to do is if "George" or "Peter" are not selected, execute $this->showOption() only once OR if "George" or "Peter" is selected, execute $this->showOptionDefault() only once.
Remember, this is not easy because the while loop executes once for each $value. In other words, it executes once for "George" and once for "Peter". So if neither is default then it does $this->showOption twice or if both are default it does $this->showOptionDefault twice or if one is default and the other is not, it does $this->showOption once and $this->showOptionDefault once so I still end up with two of the same value (in this case one selected and one not).