Jump to content

Encode table in a class or use a database?


dennis-fedco

Recommended Posts

I have a table that goes something like this;

            |     A      |     B     |       C
__________________________________________________ 

1             $x + 4      
  
2             $x + 5       $x + 5  

3             $x + 6       $x + 7       $x + 9

...

12            $x + 7       $x + 8        $x + 11

13            $x + 8       $x + 9        $x + 13


Presumably I can get the proper value this way:

$value = new MyClass($row, $col, $x);

$value = new MyClass(3, "B", 1000);  //$value === 1007

How do I best encode this table in my code?  This is related to limited physical products, so the total number of cells in the table is expected ot stay around 50.  Part of me says "jsut hardcode it right in the class itself"  but part of me is not sure. 

 

What would you suggest?

Are you expecting there to be more to the class than just this array of values? If not, a simpler lookup table function would suffice. I am not seeing any kind of established pattern, so creating a math function would not work. Therefore, hard-coding the lookup table is probably best:

$result = array(
  'A1' => 4, 'B1' => null, 'C1' => null,
  'A2' => 5, 'B2' => 5, 'C2' => null,
  'A3' => 6, 'B3' => 7, 'C3' => 9,
  ...
  'A12' => 7, 'B12' => 8, 'C12' => 11,
  'A13' => 8, 'B13' => 9, 'C13' => 13,
);
return $result[trim((string)$col) . trim((string)$row)] + $x;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.