structure to array ...

Prev Next

Function Names

structure to array, structure to array recursive

Description

This function converts a structure to an array. This is done by eliminating the member names. While structure to array affects the direct variable members only, structure to array recursive will also convert all nested members (grandchildren, etc). Numbering is based on the alphabetic order of the member names. Multiple variables can be converted with one single function call by providing all of them as function parameters. No actions are taken if the variable provided is a simple variable or contains arrays only.

Note: No protection may be applied on the variable, incl. prevent deleting, otherwise exceptions are asserted.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

Min 1

Parameters

No.TypeDescription
1, etc.
code
variable
:string
Variable name

The structure members of this variable will be converted to to array members.

Examples

  country[] = "Somewhere in Italy ...";
  structure( country[],  { Name,       Climate,       { Winter, Summer }, Language },
                         { San Marino, Mediterranean, { cool,   hot    }, Italian  } );
  temperatures[] = "And the temperatures ...";
  array( temperatures[], { 10, 30 } );

  copy[] <== country[]; // Transaction: Make copy of variable including members

  structure to array( copy[], temperatures[] );

  echo(new line, "Calling 'structure to array':");
  see( copy[] );
  see( temperatures[] ); // Is already an array

  echo(new line, "Calling 'structure to array recursive':");
  structure to array recursive( country[] );
  see( country[] );

Output

Calling 'structure to array':
copy[]                  Somewhere in Italy ...     (quoted string,full access)
Array [   0]            Mediterranean              (softquoted string,full access)
  Summer                hot                        (softquoted string,full access)
  Winter                cool                       (softquoted string,full access)
Array [   1]            Italian                    (softquoted string,full access)
Array [   2]            San Marino                 (softquoted string,full access)

temperatures[]          And the temperatures ...    (quoted string,full access)
Array [   0]            10  "10"                   (numeral,full access)
Array [   1]            30  "30"                   (numeral,full access)


Calling 'structure to array recursive':
country[]               Somewhere in Italy ...     (quoted string,full access)
Array [   0]            Mediterranean              (softquoted string,full access)
  Array [   0]          hot                        (softquoted string,full access)
  Array [   1]          cool                       (softquoted string,full access)
Array [   1]            Italian                    (softquoted string,full access)
Array [   2]            San Marino                 (softquoted string,full access)

Try it yourself: Open LIB_Function_structure_to_array.b4p in B4P_Examples.zip. Decompress before use.

See also

array to structure