Hash Tables

Started by latcheso, October 25, 2024, 12:14:48 PM

Previous topic - Next topic

latcheso

How would I assign a dynamic array to a hash table?

For example,

//Dynamic Array
DIM VALUES$
VALUES$
  • = "1"
VALUES$
  • = "2"

//Hash Table
DIM NAMES$

NAMES$["Luke"] = VALUES$

I essentially want

Key "Luke" = [1,2]







Stéphane Devouard

Hello

You can't. 
You can only assign a numeric or a string value to an associative array element

Basically, what you want is :

names$["Luke", 1] = "1"
names$["Luke", 2] = "2"

But such a syntax is invalid in PxPlus.

However if what you want is actually to convert the hash table to a JSON string, you can do it like this

->names$["Luke.1"]="1"
->names$["Luke.2"]="2"
->? dim(list edit names$)
{
  "Luke":["1","2"]
}
->
Hope this helps
Stéphane Devouard
Portfolio | Work