I have an array with around 3500 array items inside it, the format being below. I have two dynamic variables that change and I need to search the array to find out row price_value based on already knowing price_slot and country.
I've currently got the below but this is taking too long. Is there anyway I can speed up this access?
PHP Function
$country = US;
$priceSlot = 3;
$priceValue = getPriceValue($priceSlot, $country);
function getPriceValue($priceSlot, $country) {
// Search in array for price
foreach ($array as $arrayItem) {
if ($arrayItem['price_slot'] == $priceSlot && $arrayItem['country'] == $country) {
return $arrayItem['price_value'];
}
}
return null;
}
Snippet of Array
Array
(
[0] => Array
(
[price_slot] => 1
[base_price] => Get in Touch
[country] => US
[price_multiplier] =>
[price_value] => Get in Touch
)
[1] => Array
(
[price_slot] => 2
[base_price] => 9000
[country] => US
[price_multiplier] => 1.3
[price_value] => 11700
)
[2] => Array
(
[price_slot] => 3
[base_price] => 12000
[country] => US
[price_multiplier] => 1.3
[price_value] => 15600
)
[3] => Array
(
[price_slot] => 4
[base_price] => 15000
[country] => US
[price_multiplier] => 1.3
[price_value] => 19500
)
[4] => Array
(
[price_slot] => 5
[base_price] => 4000
[country] => US
[price_multiplier] => 1.3
[price_value] => 5200
)
[5] => Array
(
[price_slot] => 6
[base_price] => 1600
[country] => US
[price_multiplier] => 1.3
[price_value] => 2080
)
Is there any faster way to get around this?
Thanks!