ArrayToStruct()
Transform the array to a struct, the index of the array is the key of the struct
ArrayToStruct( array=array, valueAsKey=boolean );
Returns: Struct
| Argument | Description | Default |
|---|---|---|
|
array
array,
required
|
edit
array to translate |
|
|
valueAsKey
boolean,
optional
|
edit
use the value as the key of the struct, rather than the index Introduced: 6.0.0.79 |
false |
Examples
editSimple Array
arr = ['a','b','c','d','e','f','g'];
dump(arrayToStruct(arr));
if (listFirst(server.lucee.version,".") gte 6)
dump(arrayToStruct(arr, true));
//member function
dump(arr.toStruct());
Array of Structs
arr = [
{name:'a'},
{name:'b'},
{name:'c'},
{name:'d'},
{name:'e'}
];
dump(arrayToStruct(arr));
//member function
dump(arr.toStruct());
See also
- Arrays
- Structures
- array.toStruct()
- Search Issue Tracker open_in_new
- Search Lucee Test Cases open_in_new (good for further, detailed examples)