toBoolean([arg])
Last updated August 26, 2012
Version: 1 | Requires: CF9 | Library: StrLib
Description:
Pass me a value, expression, or anything you want and I'll give you back its boolean value (true || false). I'm especially useful when mixing CFML with JavaScript and you need an actual 'true' or 'false' value to pass in as an argument to a js call.
Return Values:
Returns a boolean: true if arg was a boolean and true, otherwise false
Example:
test = {a=[[],[]],b='1,2,3'};
toBoolean(test); // returns false
test = 'php is great';
toBoolean(test); // returns false
test = 'cfml is awesome' == 'cfml is awesome';
toBoolean(test); // returns true
Parameters:
Name | Description | Required |
---|---|---|
arg | Any value | No |
Full UDF Source:
/**
* I convert anything to boolean
* version 0.1 by Steve Withington
* version 1.0 by Adam Cameron: simplifying logic
*
* @param arg Any value (Optional)
* @return Returns a boolean: true if arg was a boolean and true, otherwise false
* @author Steve Withington (stephenwithington@gmail.com)
* @version 1, August 26, 2012
*/
public boolean function toBoolean(any arg='') {
return isBoolean(arg) && arg ? true : false;
}
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