Hi Joef5,
That's a tricky one! I think we normally suggest consulting for something this complicated, but I wanted to give this a shot.
One idea would be to use a text box field and have people enter the information exactly as you've done above with the spaces and everything. Then, on a viewer page, you can parse the field like this:
// parse price matrix field into array-of-arrays
function parsePriceMatrixLine($line) {
$line = trim($line);
if (!$line) { return array(); }
return coalesce(preg_split("/\s+/", $line), array());
}
$priceMatrix = explode("\n", $record['price_matrix']); // split string into rows
$priceMatrix = array_map('parsePriceMatrixLine', $priceMatrix); // split lines into cells
$priceMatrix = array_filter($priceMatrix); // strip blank lines
Then you can look up values like this:
function lookupPriceMatrix($priceMatrix, $rowValue, $columnValue) {
$rowIndex = @array_search($rowValue, array_pluck($priceMatrix, 0));
$colIndex = @array_search($columnValue, $priceMatrix[0]);
if (!$rowIndex || !$colIndex) { return null; }
return @$priceMatrix[$rowIndex][$colIndex];
}
For example:
$value = lookupPriceMatrix($priceMatrix, 36, 34);
showme("lookupPriceMatrix returned: $value");
Note that with this approach, you'd need to make sure that price matrix fields are filled out correctly. If someone left off the "xxx", your lookups would be incorrect.
Does that help?
All the best,
Chris