Last active
August 29, 2015 13:57
-
-
Save attitude/9768220 to your computer and use it in GitHub Desktop.
Function to check if array is associative (key-value)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "attitude/Functions/is_assoc_array", | |
"autoload": { | |
"files": ["function-is_assoc_array.php"] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to check if array is associative (key-value) | |
* | |
* @param array $array Array to check | |
* @param bool $speedy Default true, pass false to use less memory | |
* @returns bool True if associative, false if sequential | |
* @author Alix Axel <http://stackoverflow.com/users/89771/alix-axel> | |
* @see http://stackoverflow.com/questions/173400 | |
* @license CC BY-SA 3.0) <http://creativecommons.org/licenses/by-sa/3.0/> | |
* | |
*/ | |
function is_assoc_array($array, $speedy=true) | |
{ | |
if ($speedy) { | |
return ($array !== array_values($array)); | |
} | |
// More memory efficient | |
return $array = array_keys($array); return ($array !== array_keys($array)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment