How to check if array is associative or not in PHP

1 Answer

0 votes
$array = array("php"=>"99", "c"=>"108", "c++"=>"31", "python"=>"21");

if (array_keys($array) === range(0, sizeof($array) - 1)) {
    echo "not associative array";

} else {
    echo "associative array";
}


  
  
  
/*
run:
  
associative array
  
*/

 



answered Sep 23, 2023 by avibootz

Related questions

3 answers 415 views
2 answers 211 views
1 answer 211 views
1 answer 640 views
1 answer 284 views
4 answers 500 views
...