php array is assoc

Solutions on MaxInterview for php array is assoc by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "php array is assoc"
Alberto
08 Oct 2016
1function isAssoc(array $arr)
2{
3    if (array() === $arr) return false;
4    return array_keys($arr) !== range(0, count($arr) - 1);
5}
6
7var_dump(isAssoc(['a', 'b', 'c'])); // false
8var_dump(isAssoc(["0" => 'a', "1" => 'b', "2" => 'c'])); // false
9var_dump(isAssoc(["1" => 'a', "0" => 'b', "2" => 'c'])); // true
10var_dump(isAssoc(["a" => 'a', "b" => 'b', "c" => 'c'])); // true
11