/** * Processes the global matching records to find the minimum and maximum prices. * v3c: Created * @return a 2-entry associative array containing 'minPrice' and 'maxPrice'. */ function GetResultsPriceRange() { // Bring in the global array containing current item matches global $gMatchingInfo; // Fallback defaults if the array is empty, null, or not yet initialized if (!is_array($gMatchingInfo) || empty($gMatchingInfo)) { return [ 'minPrice' => 0, 'maxPrice' => 0 ]; } $minPrice = null; $maxPrice = null; foreach ($gMatchingInfo as $item) { // Look for common variations of the array keys ('minPrice' vs 'Min $') $rawMin = isset($item['minPrice']) ? $item['minPrice'] : (isset($item['Min $']) ? $item['Min $'] : null); $rawMax = isset($item['maxPrice']) ? $item['maxPrice'] : (isset($item['Max $']) ? $item['Max $'] : null); // Process Minimum Price Entry if ($rawMin !== null && trim($rawMin) !== '') { // Defensive sanitization: remove $, commas, and non-numeric fluff $cleanMin = (float) preg_replace('/[^\d.]/', '', $rawMin); if ($minPrice === null || $cleanMin < $minPrice) { $minPrice = $cleanMin; } } // Process Maximum Price Entry if ($rawMax !== null && trim($rawMax) !== '') { // Defensive sanitization: remove $, commas, and non-numeric fluff $cleanMax = (float) preg_replace('/[^\d.]/', '', $rawMax); if ($maxPrice === null || $cleanMax > $maxPrice) { $maxPrice = $cleanMax; } } } // Return the final 2-entry array (defaulting to 0 if no prices were found) return [ 'minPrice' => ($minPrice !== null) ? $minPrice : 0, 'maxPrice' => ($maxPrice !== null) ? $maxPrice : 0 ]; }