7

Possible Duplicate:
Get first key in a [possibly] associative array?

I have this array:

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

)

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

Community
  • 1
  • 1
tirenweb
  • 30,963
  • 73
  • 183
  • 303

2 Answers2

12

Other way is,

$keys = array_keys($array);

echo $keys[0];
Dr. Dan
  • 2,288
  • 16
  • 19
11

Assuming that you haven't used each(), next(), prev() or in any other manner have you advanced the array pointer:

key($array);
Narf
  • 14,600
  • 3
  • 37
  • 66