Miva Script Function: miva_array_find(...)
How to use the miva_array_find( needle, haystack var, offset ) built in mivascript function
by Scot Ranney
For this to work the array that you're searching should be a "simple" array, that is, no structures, just one value for each index item.
It's also useful to use tolower(...) and trim(...) because the the operation is the same as the EQ operator.
The script below will evaluate 2, the index of the found item.
<MvASSIGN NAME = "l.array" INDEX = "1" VALUE = "dog"> <MvASSIGN NAME = "l.array" INDEX = "2" VALUE = "cat"> <MvASSIGN NAME = "l.array" INDEX = "3" VALUE = "frog"> <MvEVAL EXPR = "{ miva_array_find('cat',l.array,0) }">
If you have an array with structures you'll need to roll through it and create a new temporary "simple" array that you can use miva_array_find(...) on.
Related Articles
These articles might be interesting for you as well: