From f45cf75407deb15bf5426c397c6d267839f91532 Mon Sep 17 00:00:00 2001 From: Andreas Gerhards Date: Mon, 18 Jun 2018 08:45:22 +1200 Subject: [PATCH] Implemented improved associative array check --- src/ORM/ArrayLib.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/ORM/ArrayLib.php b/src/ORM/ArrayLib.php index 5f83be629..572147771 100644 --- a/src/ORM/ArrayLib.php +++ b/src/ORM/ArrayLib.php @@ -123,25 +123,19 @@ class ArrayLib * Determines if an array is associative by checking for existing keys via * array_key_exists(). * - * @see http://nz.php.net/manual/en/function.is-array.php#76188 + * @see http://nz.php.net/manual/en/function.is-array.php#121692 * - * @param array $arr + * @param array $array * * @return boolean */ - public static function is_associative($arr) + public static function is_associative($array) { - if (is_array($arr) && !empty($arr)) { - for ($iterator = count($arr) - 1; $iterator; $iterator--) { - if (!array_key_exists($iterator, $arr)) { - return true; - } - } + $isAssociative = !empty($array) + && is_array($array) + && ($array !== array_values($array)); - return !array_key_exists(0, $arr); - } - - return false; + return $isAssociative; } /**