I find myself writing code such as:
foreach($array as $key => $value) {
switch($key) {
case 'something':
doSomething($value);
break;
case 'somethingelse':
doSomethingElse($value);
break;
}
}
Is there a better way to go about this? Seems dirty to me, but I might just be over thinking it.
The only other alternative that I can think of is an if statement for each key, which doesn't seem any better. I.e. :
if($array[0] == 'something') {
doSomething($array[0]);
}
if($array[1] == 'somethingelse') {
doSomethingElse($array[1]);
}
(or something like that)
I can post exact code if needed, but this is the general outline of what happens. Please critique away, but remember that I'm looking for help here. So if I'm doing something egregiously wrong, then point it out.