PDA

View Full Version : What is an easier way to do this?


Jacobb123
06-04-2008, 06:57 PM
I have an array that I need to remove certain values from so I have a while statement below that I removing one element from the loop as you will see but I have about 5 values that I need to remove and want to know a more efficient way to do this than having to create a seperate if statement for each value to be removed. Can someone suggest a way to do this?


while (list($key, $value) = each($mInfo->keys)) {


if ($value['title']!=='Which server to use') {

$keys .= '<b>' . $value['title'] . '</b><br>' . $value['description'] . '<br>';

}


if ($value['set_function'] && $value['title']!=='Which server to use') {
eval('$keys .= ' . $value['set_function'] . "'" . $value['value'] . "', '" . $key . "');");
$keys .= '<br><br>';
}


else if($value['title']!=='Which server to use') {
$keys .= tep_draw_input_field('configuration[' . $key . ']', $value['value']);
$keys .= '<br><br>';
}



else if($value['title']=='Which server to use'){

$keys .= tep_draw_hidden_field('configuration[' . $key . ']', $value['value']);


}


}

rafiki
06-04-2008, 07:07 PM
if it works why change it?

Jacobb123
06-04-2008, 07:13 PM
It works right now with a single element to be removed but like I said I have 5 to be removed and it seems sloppy to me to have a bunch of if statements is there another way to do this?

rafiki
06-04-2008, 07:15 PM
make it a function then just execute the function 5 times with the key needed to be removed set like this remove_key(keyword);

NancyJ
06-04-2008, 07:55 PM
are the values all 'title'? If so you could replace


$value['title']!=='Which server to use'


with


!in_array($value['title'], $values_to_remove)


where $values_to_remove are the values of the 'title' field to exclude