<?php
class Prices {
private $priceList = array(
/* HR EN DE FR IT ES */
/* HR */ '0 100 100 100 100 100',
/* EN */ '80 0 120 120 120 120',
/* DE */ '80 120 0 120 120 120',
/* FR */ '80 120 120 0 120 120',
/* IT */ '80 120 120 120 0 120',
/* ES */ '80 120 120 120 120 0',
);
private $coef = 1;
private $languages = array('HR', 'EN', 'DE', 'FR', 'IT', 'ES'); // Must be the same order as in $priceList
public function getRate($source, $target) {
$this->verifyPriceList();
$sourceKey = array_search($source, $this->priceList);
$targetKey = array_search($target, $this->priceList);
return intval(explode('\t', $this->priceList[$sourceKey])[$targetKey]);
}
/* $priceList must not contain spaces */
private function verifyPriceList() {
if (strstr(implode('', $this->priceList), ' ') !== FALSE)
throw Exception('Price list contains spaces! Location: class.Prices.php');
}
}
$p = new Prices();
echo $p->getRate('HR', 'EN');
?>
preferences:
38.06 ms | 402 KiB | 5 Q