Creates a new hash.
Hash( [<xKey1>, <xValue1> [, <xKeyN>, <xValueN>] ] ) --> hHash
The function returns a new hash, populated with the specified key/value pairs. If no parameter is passed, an empty hash is returned.
If the function is called with an odd number of arguments, or key values are specified which are not of data type Character, Date or Numeric, the return value is NIL.
Hash variables are usually initialized within a variable declaration using the literal Hash operator {=>}. The Hash() function is equivalent to this operator and allows for creating hashes programmatically outside a variable declaration.
Hashes can be populated with key/value pairs by passing an even number of parameters to the function. Data representing the key values must be of orderable data types which restricts them to the data types C, D and N.
| See also: | {=>}, HAllocate(), HClone(), HCopy(), HGet(), HDel(), HEval(), HSet(), HSetCaseMatch(), HGetPartition() |
| Category: | Hash functions , xHarbour extensions |
| Source: | vm\hash.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example creates hashes using the literal hash operator
// and the Hash() function.
PROCEDURE Main
LOCAL hHash1 := { "OPT1" => 10, "OPT2" => 20 }
LOCAL hHash2, hHash3
hHash2 := Hash( "OPT2", 200, "OPT3", 300, "OPT4", 400 )
hHash3 := hHash1 + hHash2
? ValToPrg( hHash3 )
// { "OPT1" => 10, "OPT2" => 200, "OPT3" => 300, "OPT4" => 400 }
RETURN
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/5b710539-7ade-4018-971c-601fbb329ec5o%40googlegroups.com.
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/6c81dc4e-c87a-43cc-a055-7ef10ccf23ado%40googlegroups.com.
Hi friend,
but my requirement was to create a NESTED structure for using with hb_jsonencode()
Only another way to do the same:
PROCEDURE Main
LOCAL a, b, c
WITH OBJECT a := hb_Hash()
WITH OBJECT b := a[ "female" ] := hb_Hash()
WITH OBJECT c := b[ "Emy" ] := hb_Hash()
c[ "money" ] := 25
ENDWITH
WITH OBJECT c := b[ "Evy" ] := hb_Hash()
c[ "money" ] := 25
ENDWITH
WITH OBJECT c := b[ "Ely" ] := hb_Hash()
c[ "money" ] := 15
ENDWITH
ENDWITH
WITH OBJECT b := a[ "male" ] := hb_Hash()
WITH OBJECT c := b[ "Huey" ] := hb_Hash()
c[ "money" ] := 10
ENDWITH
WITH OBJECT c := b[ "Dewey" ] := hb_Hash()
c[ "money" ] := 5
ENDWITH
WITH OBJECT c := b[ "Louie" ] := hb_Hash()
c[ "money" ] := 0
ENDWITH
ENDWITH
ENDWITH
hb_MemoWrit( "list2", hb_JsonEncode( a, 3 ) )
RETURN
{
"female":
{
"Emy":
{
"money": 25
},
"Evy":
{
"money": 25
},
"Ely":
{
"money": 15
}
},
"male":
{
"Huey":
{
"money": 10
},
"Dewey":
{
"money": 5
},
"Louie":
{
"money": 0
}
}
}
José M. C. Quintas
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/6d280ef6-5c6d-4415-884e-5c09b5c831ddo%40googlegroups.com.