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
scot ranney : scot at, scotsscripts d0t com
01/30/2020 20:37 p.m.
As it turns out, you can search arrays with multiple members, but you must put the value of all the members (in the right order) in the search term. The code below returns 2:
<MvASSIGN NAME = "l.petinfo:name" VALUE = "{ 'Frisky' }">
<MvASSIGN NAME = "l.petinfo:type" VALUE = "{ 'cat' }">
<MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert(l.pets,l.petinfo,-1) }">

<MvASSIGN NAME = "l.petinfo:name" VALUE = "{ 'Spot' }">
<MvASSIGN NAME = "l.petinfo:type" VALUE = "{ 'dog' }">
<MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert(l.petinfo,l.pets,-1) }">

<MvASSIGN NAME = "l.search" VALUE = "{ 'Frisky,cat' }">

Result: <MvEVAL EXPR = "{ miva_array_find(l.search,l.pets,0) }">
Ray Yates : rayyates1 at, gmail d0t com
01/09/2019 17: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 14: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) }">