I’m studying some code examples that I haven’t written myself, and I found this function which looks to me like it’s badly written, or at least not very efficient. Can you suggest ways to improve it? I was thinking this might work with an associative array, but not sure how.
Any other ways this can be re-written?
$op = '';
switch($style) {
case 'f':
case 'F': {
$op = 'f';
break;
}
case 'f*':
case 'F*': {
$op = 'f*';
break;
}
case 'B':
case 'FD':
case 'DF': {
$op = 'B';
break;
}
default: {
if (!empty($default)) {
$op = $this->dosomething($default, '');
} else {
$op = '';
}
}
}
return $op;
To use an assoc array you would need to do the following: