homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
One line conversion table
ocon




msg:4531613
 3:42 am on Dec 28, 2012 (gmt 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.

 

coopster




msg:4532204
 6:57 pm on Dec 31, 2012 (gmt 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
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved