Ok I have ten variables but one needs to be set, but I need to check for each of the values until one is set. I'm doing a SWITCH/CASE statement but I'm not sure if this is the best approach because I don't see how I can return only the variable that I need set.
$passed_var = 'A'; // Static
$var_array = getSelectedVar($passed_var);
foreach($var_array as $key => $val) {
echo "Key: " . $key . " VALUE: " . $val . "<br />\n";
}
// How do I assign one of these values?
if(isset($var_1)) {
echo "Var 1 Set<br />\n";
} elseif(isset($var_2)) {
echo "Var 2 Set<br />\n";
} elseif(isset($var_3)) {
echo "Var 3 Set<br />\n";
} elseif(isset($var_4)) {
echo "Var 4 Set<br />\n";
} elseif(isset($var_5)) {
echo "Var 5 Set<br />\n";
} elseif(isset($var_6)) {
echo "Var 6 Set<br />\n";
} elseif(isset($var_7)) {
echo "Var 7 Set<br />\n";
} elseif(isset($var_8)) {
echo "Var 8 Set<br />\n";
} elseif(isset($var_9)) {
echo "Var 9 Set<br />\n";
} elseif(isset($var_10)) {
echo "Var 10 Set<br />\n";
}
function getSelectedVar($passed_var) {
$passed_var = strtoupper($passed_var);
$update_var = array();
switch ($passed_var) {
case 'A':
case 'AB':
case 'ABC':
case 'ABCD':
$update_var_1 = 1;
$update_var = array('update_var_1'=>'1');
break;
case 'B':
case 'BA':
$update_var_2 = 1;
$update_var = array('update_var_2'=>'1');
break;
case 'C':
$update_var_3 =1;
$update_var = array('update_var_3'=>'1');
break;
case 'D':
case 'DA':
$update_var_4 =1;
$update_var = array('update_var_4'=>'1');
break;
case 'E':
$update_var_5 =1;
$update_var = array('update_var_5'=>'1');
break;
case 'F':
$update_var_6 =1;
$update_var = array('update_var_6'=>'1');
break;
case 'G':
$update_var_7 = 1;
$update_var = array('update_var_7'=>'1');
break;
case 'H':
case 'HA':
case 'HB':
$update_var_8 =1;
$update_var = array('update_var_8'=>'1');
break;
case 'I':
$update_var_9 =1;
$update_var = array('update_var_9'=>'1');
break;
case 'J':
case 'JA':
$update_var_10 =1;
$update_var = array('update_var_10'=>'1');
break;
default:
$update_var = '';
}
return $update_var;
}
Am I over complicating things???