Condensing multiple else if statements, referencing them from a table?

Posted by Haskella on Stack Overflow See other posts from Stack Overflow or by Haskella
Published on 2010-05-09T04:53:43Z Indexed on 2010/05/09 4:58 UTC
Read the original article Hit count: 256

Hi I'm about to type some 500 else if statements into my code (PHP) which have the exact same coding each:

if (color=White);
   rgb = 255-255-255;
   print rgb;
else if (color=Black);
   rgb = 0-0-0;
   print rgb;
else if (color=Red);
   rgb = 255-0-0;
   print rgb;
else if (color=Blue);
   rgb = 0-0-255;
   print rgb;
[the list keeps going]

I also (luckily) have a table that displays the color in the first column and rgb value in the next column for 500 of them... how do I use this to save time typing all those else if statements? Some how I have to reference the table file (made in excel, I'm guessing I'll have to save it as .csv?)

© Stack Overflow or respective owner

Related posts about beginner

Related posts about if