I need to do a series of comparisons with an integer in PHP, returning a different string depending on the result and I am wondering if an if..else block is the most elegant method. The code looks like:
if( $total < 10000 ) {
return 'string A';
} elseif( $total < 20000 ) {
return 'string B';
} elseif( $total < 30000 ) {
return 'string C';
} elseif( $total < 40000 ) {
return 'string D';
} elseif( $total < 50000 ) {
return 'string E';
}
Which works, I just don't think it's very pretty. If I was doing equality checks then I would use a switch block.