that's a good idea, but two things:
- i think you mixed up the if-clause
(If our new keys equal our old keys then it's not associative, and vice versa)
- the foreach-loop only tests the first key
so i think your function is identical to this one:
function isAssociative($array)
{
return (key($array) == "0") ? FALSE : TRUE;
}
to test each key you could use something like:
function isAssociative($array)
{
$keys = array_keys($array);
$ass = TRUE;
foreach ($keys as $key => $value) {
if (strcmp($key, $value) == 0) $ass = FALSE;
}
return $ass;
}
but these functions fail for:
$c = array("0" => "a", "1" => "b");
or
$c = array(0 => "a", 1 => "1");
but i think, it's the best you can do. i have no other idea.
thanx a lot
joe