I’m not sure a switch-case would work, as you are needing to do a comparison to determine which fee amount to apply. switch statements accept a value and you can then create case statements for the values you expect and perform different operations.
Another technique you could utilize is using an array to store your price threshold and the fee associated when that threshold is met, then you can loop through the array to determine which fee to apply. However, that is really just hiding the underlying process you are trying to do, and the if/else statements are much clearer to their intent from a readability stand point.
So I guess, my recommendation is to leave it as is, or possibly place it in a table that you can run a query against (again, really is somewhat hiding the process, but the query will be just as readable as to its intent).
How often are these fees going to change? You might want to consider putting them into a database table. If you would setup the table with a minimum and maximum dollar amount, you could do it in one query ($result = mysql_query(“SELECT fee FROM AddtionalFee WHERE " . $price . " IS BETWEEN LowPrice and HighPrice”);).
Then if you want to change the fees or add a range, you just have to make a database change.
I agree. The best (cleanest) way to solve this is to do away with the current fee structure and get a formula instead, but I don’t think that’s an option.
Thanks Aaarrrggh. I think that might have been more what I had in mind but, yes, whether it’s any more readable… Anyway, thanks for an alternative way to code it…