Returns the character string key for the first element of an associative array.

Property of

AssocArray

Description

Use firstKey when you want to loop through the elements in an associative array. Once you have gotten the key value for the first element with firstKey, use nextKey( ) to get the key values for the rest of the elements.

Note

The order of elements in an associative array is undefined. They are not necessarily stored in the order in which you add them, or sorted by their key values. You can't assume that the value returned by firstKey will be consistent, or that it will return the first item you added.

For an empty associative array, firstKey is the logical value false. Because false is a different data type than valid key values (which are character strings), it requires extra code to look for false to see if the array is empty. It’s easier to get the number of elements in the array with count( ) and see if it’s greater than zero.