From: Frederik Ramm Date: Thu, 6 May 2021 18:44:04 +0000 (+0200) Subject: Add array_key_last function for PHP <7.3 X-Git-Tag: v4.0.0~86 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/fe39185894cc7c7f1d4d50b15cc96476b35641d9?ds=sidebyside;hp=--cc Add array_key_last function for PHP <7.3 This patch adds an array_key_last function if it doesn't yet exist, fixes #2316. It is tested on PHP 7.2.24 but not PHP 7.3. --- fe39185894cc7c7f1d4d50b15cc96476b35641d9 diff --git a/lib-php/lib.php b/lib-php/lib.php index a1f528fa..8d82c5b3 100644 --- a/lib-php/lib.php +++ b/lib-php/lib.php @@ -227,3 +227,10 @@ function closestHouseNumber($aRow) return max(min($aRow['endnumber'], $iHn), $aRow['startnumber']); } + +if (!function_exists('array_key_last')) { + function array_key_last(array $array) + { + if (!empty($array)) return key(array_slice($array, -1, 1, true)); + } +}