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 264 views
2 answers 92 views
1 answer 106 views
1 answer 558 views
1 answer 182 views
4 answers 301 views
...