Built From Developers For Developers
» Kuikie.com » Snippets » PHP » Arrays » PHP. Find if Array is Associative
  Categories
  PHP
    Arrays
    Date & Time
    Files & Directories
    Globalization
    Images
    OOP
    Other
    Strings
    User Interface
 

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 ===========================//
 
©2012 Sinevia Ltd Terms of Use         Privacy Policy Valid XHTML 1.0 Transitional