FirstInFirstOut(array, valueToAdd)
Last updated May 13, 2003
Version: 1 | Requires: CF5 | Library: DataManipulationLib
Description:
Deletes the first element in a given array, then inserts a new element at the end of the array, creating a first in first out effect.
Return Values:
Returns an array.
Example:
<cfset myArray = ArrayNew(1)>
<cfset myArray[1] = "First In">
<cfset myArray[2] = "Second In">
<cfset myArray[3] = "Third In">
<cfset myArray[4] = "Fourth In">
<cfoutput>
Before:<br>
<cfloop from="1" to="#ArrayLen(myArray)#" index="i">
#myArray[i]#<br>
</cfloop>
</cfoutput>
<cfset myArray = FirstInFirstOut( myArray, "New Value" )>
<cfoutput>
<br>After:<br>
<cfloop from="1" to="#ArrayLen(myArray)#" index="i">
#myArray[i]#<br>
</cfloop>
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
array | Array to modify. | Yes |
valueToAdd | Value to add. | Yes |
Full UDF Source:
/**
* Removes the element at index one and inserts a new element at the highest index plus one.
*
* @param array Array to modify. (Required)
* @param valueToAdd Value to add. (Required)
* @return Returns an array.
* @author Adrian Lynch (adrian.l@thoughtbubble.net)
* @version 1, May 13, 2003
*/
function FirstInFirstOut( array, valueToAdd ) {
// Delete element at index 1
ArrayDeleteAt( array, 1 );
// Add new element at last index plus one
array[ArrayLen( array ) + 1] = valueToAdd;
return array;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016