I have a JSON array like this:
[
{"location":"1","distance":"25.75206"},
{"location":"2","distance":"21.49343"},
{"location":"3","distance":"24.13432"}
]
Right now I am doing a foreach with every $location to get the corresponding data.
$locations = json_decode($locations, true);
foreach ($locations as $key => $value) {
if ($value['location'] == $location) {
$distance = $value['distance'];
}
}
The problem is, the arrays can be very big with several thousand items, so doing a foreach is quite resource intensive and can slow things down.
Is there any more "direct" and less resource intensive way of getting each corresponding value?