We have a variable $country, it can give ~ 50 different values.
And a variable $id.
We need to give a value $idcorresponding to the value $country, for example:
if ($country = 'USA') { $id = 'usa_type'; }
else if ($country = 'France') { $id = 'france_type'; }
else if ($country = 'German') { $id = 'german_type'; }
else if ($country = 'Spain') { $id = 'spain_type'; }
...
...
...
else if ($country = 'Urugway') { $id = 'urugway_type'; }
else { $id = 'undefined'; }
Operatorelse if repeated every time, and other data is typical.
Is there any way to make this code shorter?
how
[france]:'france_type;
[england]:'england_type;
...
[else]:'undefined'
Thank.
source
share