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?)
Your best bet is to put that data (color name to RGB value) into a database, then just do:
If you can’t do a database, you could use
fgetcsv()and read CSV data into an array. Then just output:To read a CSV file into an array, use something like: