Skip to content

Commit 10dd4e6

Browse files
committed
#29 - Add test for associative arrays
1 parent 86df3b8 commit 10dd4e6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/TgUtils/Utils.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,14 @@ public static function isEmpty($s) {
121121
return strlen(trim($s)) == 0;
122122
}
123123

124+
/**
125+
* Checks whether an array is associative or not.
126+
* @param array $arr - the array to be tested
127+
* @return boolean TRUE - when array is associative, FALSE otherwise
128+
*/
129+
public static isAssoc(array $arr) {
130+
if (array() === $arr) return FALSE;
131+
return array_keys($arr) !== range(0, count($arr)-1);
132+
}
133+
124134
}

0 commit comments

Comments
 (0)