Friday, March 02, 2012

Associative Array Assignments

Associative Array Assignments

Associative arrays can be assigned only to another associative array of a compatible type and with the same index type. Other types of arrays cannot be assigned to an associative array, nor can associative arrays be assigned to other types of arrays, whether fixed-size or dynamic.

Assigning an associative array to another associative array causes the target array to be cleared of any existing entries, and then each entry in the source array is copied into the target array.

Associative Array Arguments:

Associative arrays can be passed as arguments only to associative arrays of a compatible type and with the same index type. Other types of arrays, whether fixed-size or dynamic, cannot be passed to subroutines that accept an associative array as an argument.

Likewise, associative arrays cannot be passed to subroutines that accept other types of arrays. Passing an associative array by value causes a local copy of the associative array to be created.

Associative Array Literals:

Associative array literals use the {index:value} syntax with an optional default index. Like all other arrays, an associative array can be written one entry at a time, or the whole array contents can be replaced using an array literal.

NOTE:

array.num( ) - Returns number of entries in the associative array.

array.delete(N) - if index N is not specified, deletes all elements of the array. If index N is specified, deletes only that particular element.

array.exists(N) - checks if element exists at that particular index of the array. returns 1 if true. index is mandatory

array.first(N) - assigns to the index variable N the value of the smallest index in the array, returns 1 if array is not empty, 0 otherwise

array.last(N) - assigns to the index variable N the value of the largest index in the array, returns 1 if array is not empty, 0 otherwise

array.next(N) - finds the entry whose index is greater than current index N and assigns the index variable to that next entry. Returns 1 if true

array.prev(N) - finds the entry whose index is smaller than current index N and assigns the index variable to that previous entry. Returns 1 if true

No comments:

Post a Comment

Popular Posts