OpenBD Wiki

From OpenBD
Jump to: navigation, search

ArrayTrim()

This function quickly reduces the size of an array to a given size, chopping off the elements at the end accordingly.

It is a very quick way of allowing an Array to operate as a circular queue or fixed size FIFO queue.

Contents

Parameters

ArrayTrim( array, size )

  • array: the array to operate on
  • size: the maximum elements

Returns

This function returns true

Example

<cfset myArray = ArrayNew(1)>
<cfloop index="x" from="1" to="20">
  <cfset ArrayAppend( myArray, x )>
</cfloop>

<cfdump var=#myArray#>

<cfset ArrayTrim( myArray, 5 )>
<cfdump var=#myArray#>

Notes

If the size is greater than the number of elements in the array, then the array is not touched. If the size is less than or equal to 0, then the array is completely emptied.

Engine Compatibility

  • OpenBD 1.0+

Personal tools