miva_array_insert()

 
Inserts single element "element" into "array" at position "pos". If "pos" = -1, the element is inserted at the end of "array".
Syntax
miva_array_insert( array var, element, pos )
Returns the number of elements in "array" after the insertion.
  • array = The array tro which the records will be inserted
  • element = the record that will be inserted
  • pos = the index where the element will be inserted.
User Annotations: miva_array_insert
Ray Yates : ryates at, miva d0t com
01/09/2019 17:59 p.m.
The element parameter can be confusing, where element can be a simple variable or an entire structure.

In the second example below we create l.record with multiple members, then insert the record into the array.
Create a simple array:
<MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert( l.search_engines , 'google', '-1' )" }" = "}"">
<MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert( l.search_engines , 'bing', '-1' )" }" = "}"">

l.search_engines[1] = google
l.search_engines[2] = bing

To insert a structure:
<MvFOREACH ITERATOR = "l.item" ARRAY = "l.products">
	<MvASSIGN NAME = "l.record:code" VALUE = "{ l.item:code }">
	<MvASSIGN NAME = "l.record:name" VALUE = "{ l.item:name }">
	<MvASSIGN NAME = "l.ok" VALUE = "{ miva_array_insert( l.myproducts , l.record, '-1' )" }" = "}"">
</MvFOREACH>

l.myproducts[1]:code = product code
l.myproducts[1]:name = product name
l.myproducts[2]:code = product code
l.myproducts[2]:name = product name