– Common Function Library Project

Dump(var[, expand][, label][, top])

Last updated October 16, 2002


Raymond Camden

Version: 2 | Requires: CF6 | Library: CFMLLib

Mimics the cfdump tag, but adds new "top" attribute.

Return Values:
Returns a string.


<cfset x = arraynew(1)>
<cfloop index="y" from=1 to=200>
	<cfset x[y] = randRange(1,1000)>

dump(var=x,label="The Array X",top=10);


Name Description Required
var The variable to dump. Yes
expand Expand output. Defaults to true. No
label Label for dump. No
top Restricts output based on type. If array or query, top will represent the number of rows to show. If structure, will show this many keys. No

Full UDF Source:

 Mimics the cfdump tag.
 Updated for final cfmx var scope - also, we only redo var if size bigger than top.
 @param var 	 The variable to dump. (Required)
 @param expand 	 Expand output. Defaults to true. (Optional)
 @param label 	 Label for dump. (Optional)
 @param top 	 Restricts output based on type. If array or query, top will represent the number of rows to show. If structure, will show this many keys. (Optional)
 @return Returns a string. 
 @author Raymond Camden ( 
 @version 2, October 16, 2002 
<cffunction name="dump" returnType="string">
	<cfargument name="var" type="any" required="true">
	<cfargument name="expand" type="boolean" required="false" default="true">
	<cfargument name="label" type="string" required="false" default="">
	<cfargument name="top" type="numeric" required="false">
	<!--- var --->
    <cfset var type = "">
    <cfset var tempArray = arrayNew(1)>
    <cfset var temp_x = 1>
    <cfset var tempStruct = structNew()>
	<cfset var orderedKeys = "">
	<cfset var tempQuery = queryNew("")>
	<cfset var col = "">
	<!--- do filtering if top ---->
	<cfif isDefined("top")>
		<cfif isArray(var)>
			<cfset type = "array">
		<cfif isStruct(var)>
			<cfset type="struct">
		<cfif isQuery(var)>
			<cfset type="query">
		<cfswitch expression="#type#">
			<cfcase value="array">
				<cfif arrayLen(var) gt top>
					<cfloop index="temp_x" from=1 to="#Min(arrayLen(var),top)#">
						<cfset tempArray[temp_x] = var[temp_x]>
					<cfset var = tempArray>
			<cfcase value="struct">
				<cfif listLen(structKeyList(var)) gt top>
					<cfset orderedKeys = listSort(structKeyList(var),"text")>
					<cfloop index="temp_x" from=1 to="#Min(listLen(orderedKeys),top)#">
						<cfset tempStruct[listGetAt(orderedKeys,temp_x)] = var[listGetAt(orderedKeys,temp_x)]>
					<cfset var = tempStruct>
			<cfcase value="query">
				<cfif var.recordCount gt top>
					<cfset tempQuery = queryNew(var.columnList)>
					<cfloop index="temp_x" from=1 to="#min(var.recordCount,top)#">
						<cfset queryAddRow(tempQuery)>
						<cfloop index="col" list="#var.columnList#">
							<cfset querySetCell(tempQuery,col,var[col][temp_x])>
					<cfset var = tempQuery>
	<cfdump var="#var#" expand="#expand#" label="#label#">
blog comments powered by Disqus


Latest Additions

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Simon Bingham added
April 15, 2015

Umbrae added
February 11, 2015

Mosh Teitelbaum added
January 8, 2015

Created by Raymond Camden / Design by Justin Johnson