mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merged revisions 47807 via svnmerge from
svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq ........ r47807 | ischommer | 2008-01-10 14:07:06 +1300 (Thu, 10 Jan 2008) | 1 line added is_associative() ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47810 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
f2d38ee016
commit
baefbd1b96
@ -67,6 +67,23 @@ class ArrayLib extends Object {
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param array $arr
|
||||
* @return boolean
|
||||
*/
|
||||
static function is_associative($arr) {
|
||||
if(is_array($arr) && ! empty($arr)) {
|
||||
for($iterator = count($arr) - 1; $iterator; $iterator--) {
|
||||
if (!array_key_exists($iterator, $arr)) return true;
|
||||
}
|
||||
return !array_key_exists(0, $arr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user