$GETKEYFROMARRAY (get key information from array)
$GETKEYFROMARRAY acquires the key of a specified array number from keyed information stored in an array.
Syntax
return-value=$GETKEYFROMARRAY(array-name,array-number)
Values
-
return-value
Specifies the name of the variable into which the acquired key is set.
-
array-name
Specifies the variable name of the array variable from which key information is read.
-
array-number
Specifies a numeric character, either as a constant or a variable. A constant must be enclosed in single quotation marks (''). Specified values can range from 1 to 2,147,483,647.
If no array element exists for the specified array number, a 0-byte character string is returned.
Status
The following table lists and describes the possible statuses:
Status |
Description |
---|---|
NORMAL |
Normal end |
NODATA |
No information exists for the specified array number. |
ERROR |
— |
Script execution interrupted |
An invalid argument was specified, or an error other than the above occurred. |
Example
The following example acquires the key information and value of the fifth element of the array variable ARY:
[SET_VALUE] $CLEARARRAY(ARY) $SETARRAYBYKEY(ARY,'CPU','100') # ARY[1] CPU[1] $SETARRAYBYKEY(ARY,'CPU','200') # ARY[2] CPU[2] $SETARRAYBYKEY(ARY,'HD' ,'40') # ARY[3] HD[1] $SETARRAYBYKEY(ARY,'HD' ,'20') # ARY[4] HD[2] $SETARRAYBYKEY(ARY,'MEM','128') # ARY[5] MEM[1] $SETARRAYBYKEY(ARY,'MEM','256') # ARY[6] MEM[2] KEY = $GETKEYFROMARRAY(ARY,5) VAL = $GETARRAY(ARY, 5) MSG = 'ARY[5]: KEY=' + KEY + ' VAL=' + VAL $ECHO(MSG)
- Execution result:
-
ARY[5]: KEY=MEM VAL=128