0

I have a table of values like this:

http://www.conversiontable.org/clothingsizeconversiontable.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?

2 Answers 2

1

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 ;)

3
  • the problem is that the admin of the site doesn;t introduce only one type of sizes. he may introduce any type of size, and the conversion must be done automatically. so if i declare like in the previous example, i must make a huge vector
    – dana
    Mar 17, 2011 at 10:03
  • What do you mean with "any type of size"? I thought the sizes followed a standard :p Being that the case I understand that the sizes data is dynamic, so I would try a database-based approach rather than plain arrays. Maybe you can improve your question by adding more information
    – elitalon
    Mar 17, 2011 at 10:27
  • yep. they are stored in the database (the values if the array). i guess i 'll try using the second approach, but with more dimensions: something like: 'women' => array( 'coats_dresses_suits' => array( 'US' => 6, 'UK' => 28, 'CONTINENTAL'=>34,
    – dana
    Mar 17, 2011 at 10:53
1

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]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.