miva_array_search()#
Syntax
miva_array_search( array var, offset, element var, filter_expr )
Returns#
Returns the index of the first element in “array” for which filter_expr
evaluated as true, or 0 if no elements met this condition.
Parameters#
Parameter | Description |
---|---|
array var |
the array that will be searched |
offset |
the starting index for the search |
element var |
a variable name used to reference individual array records. See Example 1 |
filter_expr |
an expression similar to the EXPR attribute to MvFILTER . See Example 2 |
The element
parameter provides the variable name for the individual elements in the array when evaluating the filter expression. It is a var
parameter which is made a reference to each element in the array before evaluating the expression.
Examples#
Example 1#
Given l.data
as a structured array:
l.data[n]:id
l.data[n]:name
l.data[n]:amount
<MvIF EXPR = "{ miva_array_search( l.data, 1, l.element, 'l.element:id EQ 99' ) }">
<MvEVAL EXPR="{ l.element:id}">, <MvEVAL EXPR="{ l.element:name}">, <MvEVAL EXPR="{ l.element:amount}"><br>
<MvELSE>
Record not found.
</MvIF>
The filter_expr
parameter is an expression similar to the EXPR attribute to MvFILTER. The expression is executed in the same state as the caller of miva_array_search()
. All local variables within that context are available and function calls are permitted.
Example 2#
<MvASSIGN NAME = "l.array" INDEX = 1 VALUE = "wombat">
<MvASSIGN NAME = "l.array" INDEX = 2 VALUE = "badger">
<MvASSIGN NAME = "l.array" INDEX = 3 VALUE = "beaver">
<MvASSIGN NAME = "l.badger_pos" VALUE = "{ miva_array_search( l.array, 1, l.element, 'toupper( l.element ) EQ \'BADGER\'' ) }">