Snippet. PHP. Find if Array is Associative
This PHP function will help you find, if an array is associative or not.
//======================== START OF FUNCTION ==========================//
// FUNCTION: is_assoc //
//=====================================================================//
/**
* Checks, if an array is associative
* @param $array the array to be tested
* @return Boolean true, if the array is associative, false otherwise
*/
function is_assoc($array) {
if (is_array == false) return false;
return (count($array)==0 || 0 !== count(array_diff_key($array, array_keys(array_keys($array)))));
}
//=====================================================================//
// FUNCTION: is_assoc //
//========================= END OF FUNCTION ===========================//
Updated on: 03 Nov 2025 |
|
|