Miva Merchant SEO, eCommerce, Miva Modules, Custom Web Apps, and Miva Merchant troubleshooting.

Miva Merchant & Miva Script News

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

by
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.


(0/5, vote) my rating:
overall rating:

Please log in to leave a comment.

The blog posts on Scot's Scripts are served by Scot's Blogger, a Miva Merchant blogging module that makes it easy to create a Wordpress style blog, rich content, and extra pages in your Miva Merchant store.