I have written the following code to check whether an array is associative or not
function is_associative( $arr ) {
$arr = array_keys( $arr );
return $arr != array_keys( $arr );
}
It returns true for arrays like:
array("a" => 5,"b" => 9);
and false for numeric arrays
But it doesn't return true for associative arrays with single element like:
array("a" =>9);
Why does it returns false for associative arrays with single element?
array_diff
– alfasin Jul 5 '12 at 19:49