Welcome to WebmasterWorld Guest from 54.145.13.215

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

One line conversion table

     
3:42 am on Dec 28, 2012 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:222
votes: 0


I have numbers representing strings that I would like to convert back into their strings.

Right now I am using:

$sense = array('', 'sight', 'hearing', 'touch', 'smell', 'taste');
echo $sense[$number]; // 3 => touch


I do not use the $sense array anywhere else and I have several one-time use arrays like this.

Is there some super awesome function that I can use to turn this into a one liner to help declutter my code? I do not need to use arrays if there is something more appropriate.
6:57 pm on Dec 31, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


You could write your own I suppose. Pass in the array name and the number and return your value. Something like ...
function getMyString($array, $number) 
{
if (isset($GLOBALS[$array][$number])) {
return $GLOBALS[$array][$number];
}
return false; // handle non-existent value
}