views:

114

answers:

2

I'm setting up a spacing structure for some text on an image. So I have to set a $s value for every letter of the alphabet (lower and uppercase) so that is 52 statements.

If I go this route the elseif statement list is going to be huge...

Is there a better way to do this to help shorten the code that finds the $s value depending on the $char value?

Thank you.

+9  A: 

Use an associative array:

$map = array('a' => 'value', 'b' => 'other value', ...);
$char = 'a';
$settingForChar = $map[$char]; // value
Gordon
Here is some [documentation](http://php.net/manual/en/language.types.array.php) on it.
NullUserException
A: 

I may be misunderstanding what you are hoping to accomplish, but couldn't you just use a monospace font, or is that not an option here? Then you know the spacing, it's the same for every character.

The Mirage