fetch(PDO::FETCH_ASSOC)) { $tmp[(int)$row['locationid']][$row['setting']] = $row['value']; } // $matchingLocations contains the location ids sorted from closest to furthest, so we use it to make sure the order // in which they override is correct (closest setting wins, e.g. room setting beats department setting) $prio = count($matchingLocations) + 1; foreach ($matchingLocations as $lid) { if (!isset($tmp[$lid])) continue; ConfigHolder::setContext('location-' . $lid); foreach ($tmp[$lid] as $setting => $value) { ConfigHolder::add($setting, $value, $prio); } $prio -= 1; } unset($tmp); }