Get index name in array

Possible duplicate:
Get the first key in an [possibly] associative array?

I have this array:

Array ( ['foobar'] => Array ( [key1] => value1 [key2] => value2 ) ) 

I want to get the name of the first index (foobar). How can i do this?

+4
source share
2 answers

Assuming you did not use each() , next() , prev() or in any other way, you pointed to a pointer to an array:

 key($array); 
+6
source

Another way:

 $keys = array_keys($array); echo $keys[0]; 
+8
source

All Articles