I have following list:
$radiusList = [
'2' => '2km',
'5' => '5km',
'10' => '10km',
'25' => '25km',
'50' => '50km',
'100' => '100km',
'200' => '200km',
'500' => '500km',
];
I am getting currently selected radius via POST:
$radius = $_POST['radius'] ? $_POST['radius'] : 2;
And I have to go to the next radius if the result is empty. This is my do/while loop:
$clinics = [];
$radiusCount = count($radiusList);
$i = 0;
do {
$radius = $radiusList[$radius];
$clinics = $this->clinicQuery($conditionsQuery, $lat, $lng, $radius);
$i++;
} while (!empty($clinics) && $i <= $radiusCount);
How can I set current radius (from the radius list) and if the result from the clinicQuery is empty go to the next element in the array and take key value?
kmanyway) … Make that$radiusList = [2, 5, 10, …]instead, and then simply find the index of your POSTed value in that, and use it as starting value for$i, so that inside your loop you can use that index to access the values.