well, there are four ways I'd suggest. Here they are in order of speed and maintainability, from worst to best, and subsequently in reverse order from easiest to most challenging / least flexible:
1) use switch/case instead of if/elseif
[
php.net...]
anecdotal evidence says that a switch/case is possibly slower than an if/else, but it's a nice way to organize a large block of conditional controls
2) define all your pages as an array, like this:
$map = array(
'page1.html'=>'001', 'page2.html'=>'002',
'page2.html'=>'003', 'page3.html'=>'004'
...
);
then,
$page = $map[$ref];
Arrays are fast, and compared to an if/else/switch/case it's definitely less cluttery. Arrays don't scale particularly well since the whole array has to be defined at runtime and held in memory - even though you'll only be using one element in the array.
3) store the page mapping in MEMCACHE, or SQLITE, and look them up.
SQLite uses memory caching very efficiently - it's faster than a MySQL database, though it doesn't have the convenience of nifty software for manipulating your data.
[
php.net...]
Memcache is a simple key->value storage that's 100% in memory. Data retrieval doesn't get any faster.
[
php.net...]
4) if the mapping of pages follows a consistent pattern, do it algorithmically.
$page = str_pad( substr($ref,4,strpos($ref,".")), 3, "0");
an algorithm requires no storage, requires no extra resources, and scales infinitely.