开发者

php table of values

I have a table of values like this:

http://www.conversiontable.org/clothingsizeconversiontab开发者_如何学Pythonle.html

and I want to declare these values in a php class and then manipulate them easily.

In your opinion, what is the best way to do such thing?


You can build an array indexed by country name and then by size number:

$country_sizes = array(
    'United States' => array(6, 8, 10, 12, 14, 16, 18),
    ...
)

But in order to avoid mistakes and make the code more readable, I would assign a label to each size type. Then I would build an array indexed by size type first, and then by country:

$sizes = array(
    'S' => array(
        'United States' => 6,
        'United Kingdom' => 28,
        ...
    ),
    'M' => array(
        'United States' => 8,
        'United Kingdom' => 30,
        ...
    ),
    ...
);

This second way is more tedious to build, but seems more natural to me (what's the S size in U.K.?). Anyway, it's your choice according to your needs ;)


something like:

$sizes = array(
  'United States' => array(6, 8, 10, 12, 14, 16, 18),
  'United Kingdom' => array (28, 30, 32, 34, 36, 38, 40)
);

echo('United states first size: ' . $sizes['United States'][0]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜