Miva Script Function: miva_array_find(...)

Miva Merchant Modules and Development
Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

Miva Script Function: miva_array_find(...)

How to use the miva_array_find( needle, haystack var, offset ) built in mivascript function

by Scot Ranney • June 26, 2018

Miva Merchant, Miva Scripting 101


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.


overall rating:
my rating: log in to rate

mivascript tutorial

The blog posts on Scot's Scripts are made using by Scot's Blogger, a full featured Wordpress replacement Miva Merchant blogging module.