Better "if statement" structure
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开发者_StackOverflow中文版 there a better way to do this to help shorten the code that finds the $s value depending on the $char value?
Thank you.
Use an associative array:
$map = array('a' => 'value', 'b' => 'other value', ...);
$char = 'a';
$settingForChar = $map[$char]; // value
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.
精彩评论