miva_array_find()

 
Performs a sequential search for "needle" in array "haystack", starting at "offset". Comparison is equivalent to the EQ operator. (i.e. looks for an exact match). Haystack must be a simple array( no members), or contain no more than 1 member.
Syntax
miva_array_find( needle, haystack var, offset )
Returns the index of "needle" in "haystack" or 0 if the element was not found.
  • needle = value to search for
  • haystack var = the simple array to search
  • offset = the starting index position
User Annotations: miva_array_find
Ray Yates : rayyates1 at, gmail d0t com
01/09/2019 16:36 p.m.
Testing shows you can search a structured l.array, If there is ONLY ONE MEMBER. As soon as another member is added to the l.array it will fail.
<MvASSIGN NAME = "l.array" INDEX = "1" MEMBER = "pet" VALUE = "dog">
<MvASSIGN NAME = "l.array" INDEX = "2" MEMBER = "pet" VALUE = "cat">
<MvASSIGN NAME = "l.array" INDEX = "3" MEMBER = "pet" VALUE = "fish">

<MvEVAL EXPR = "{ miva_array_find('cat',l.array,0) }">

Outputs 2
scot ranney : scot at, scotsscripts d0t com
06/26/2018 13:57 p.m.
The array to be searched needs to be a "simple" array- no structures.

The script below will evaluate 2, the index of the found item. 

Trim and tolower is useful here because it's looking for an exact match.
<MvASSIGN NAME = "l.array" INDEX = "1" VALUE = "dog">
<MvASSIGN NAME = "l.array" INDEX = "2" VALUE = "cat">
<MvASSIGN NAME = "l.array" INDEX = "3" VALUE = "tree">

<MvEVAL EXPR = "{ miva_array_find('cat',l.array,0) }">