我會創建這樣的
$dataPoints = array(
array(
'point' => 1,
'price' => 1.5,
'country' => 'UK'
),
array(
'point' => 1,
'price' => 1.3,
'country' => 'US'
),
array(
'point' => 1,
'price' => .8,
'country' => 'SWEDEN'
),
...
)
陣列而像
function getPrice($pricePoint, $country) {
// Search in array for good price
foreach ($dataPoints as $dataPoint) {
if ($dataPoint['point'] == $pricePoint && $dataPoint['country'] == $country) {
return $dataPoint['price'];
}
}
return null;
}
一個功能,與你的訊息參數稱它爲打印
$pp = filter_input(INPUT_POST, 'price_point');
$country = filter_input(INPUT_POST, 'country_name');
$price = getPrice($pp,$country);
echo 'Country is ', $country, '. The price point is ', $pp, '. The price is ', $price;
閱讀PHPexcel閱讀和寫入Excel表。否則,您將需要使用像mysql這樣的數據庫(並將phpmyadmin作爲MySQL的gui)並查詢它是最佳方式。使用phpexcel,您可以將電子表格導入到數組或對象中,使用php進行修改並將其導出。 – Nitin
您需要使用數組的索引進行最快搜索$ arr = array('US'=> [...],'UK'=> [...]);或根據搜索參數動態重新排列陣列 – Nitin