| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Retrieves the sort order of a key in an associative array.
HaaGetRealPos( <hArray>, <nPos> ) --> nSortOrder
The function returns a numeric value representing the sort order of <xKey> in the associative array <hArray>, or 0 if the key does not exist.
Keys are internally held in an associative array by their sorting order. Function HaaGetRealPos() is used to determine this sorting order of a key in an associative array. The ordinal position of a key is returned by HaaGetPos().
| See also: | Array(), HaaGetKeyAt(), HaaGetPos(), HaaGetValueAt(), HaaSetValueAt(), Hash(), HGetVaaPos(), HSetAACompatibility() |
| Category: | Associative arrays , Hash functions , xHarbour extensions |
| Source: | vm\hash.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example outlines the difference of the ordinal position
// of a key and its sorting order in an associative array
PROCEDURE Main
LOCAL hArray := Hash(), i, nReal
HSetAACompatibility( hArray, .T. )
hArray[ "One" ] := 10
hArray[ "Two" ] := 20
hArray[ "Three"] := 30
hArray[ "Four" ] := 40
hArray[ "Five" ] := 50
FOR i:=1 TO Len( hArray )
? i, HGetKeyAt( hArray, i )
NEXT
** Output:
// 1 Five
// 2 Four
// 3 One
// 4 Three
// 5 Two
FOR i:=1 TO Len( hArray )
nReal := HaaGetRealPos( hArray, i )
? nReal, HGetKeyAt( hArray, nReal )
NEXT
** Output:
// 3 One
// 5 Two
// 4 Three
// 2 Four
// 1 Five
RETURN
http://www.xHarbour.com