Jump to content

Encode table in a class or use a database?


dennis-fedco
Go to solution Solved by bsmither,

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?

Link to comment
Share on other sites

  • Solution

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;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.