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 |
ArrayTrim( array, size )
This function returns true
<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#>
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.