Its late and I can't figure out how to do this.
I have an array like
Array
(
[0] => Array
(
[key] => sad
[value] => sadd
[default] => 1
)
[1] => Array
(
[key] => hap
[value] => hagp
[default] => 1
)
[2] => Array
(
[key] => blda
[value] => bla
)
[3] => Array
(
[key] => as
[value] => as
)
)
which builds a list/menu. When I submit it I want to redisplay the new selected feilds which say look like.
This is me selecting those two options and submitting
[menu] => Array
(
[0] => sad
[1] => blda
)
Now I wrote code to loop through the first array and then loop through the second submitted one to compare each option against the POST array values to see whats selected. The problem is I build a string after it finds a match or doesn't. If I select more then 1 item, the next time my form rebuilds it duplicates the same options until it finds a match. I can't think of a way to only pick to select the item or not after it ran all of its conditions. I break the loop if it finds it which works that way but I can't do that when it doesn't find that because it "might" on the next go round.
foreach($value_name as $data)
{
if( isset( $this->method[$name] ) )
{
if( is_array( $data ) )
{
foreach($this->method[$name] as $o)
{
if( $o == $data['key'] )
{
$value .= "<option value=\"{$data['key']}\" selected=\"selected\">{$data['value']}</option>\n";
break 1;
}
else
{
$value .= "<option value=\"{$data['key']}\">{$data['value']}</option>\n";
}
}
I swear I have done this b4 but can't recal where, maybe im just too tired doing this all day. If anyone has an idea on how to solve this let me know, thank you.