Alex Rivera | Logout

Getting the key of the only element in a PHP array

Asked 2010-02-16T07:00:52.457
14

The key of the associative array is dynamically generated. How do I get the "Key" of such an array?

$arr = array ('dynamic_key' => 'Value');

I am aware that It is possible to access it through a foreach loop like this:

foreach ($arr as $key => $val) echo "Key value is $key";

However, I know that this array will have only one key and want to avoid a foreach loop. Is it possible to access the value of this element in any other way? Or get the key name?

Edit
Report

1 Answer

0

What about array_keys()?

It does return an array though...

answered 2010-02-16T07:04:14.650

Your Answer