FirstInFirstOut(array, valueToAdd)
Last updated May 13, 2003
Version: 1 | Requires: ColdFusion 5 | 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[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:
<cfscript>
/**
* 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;
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)