Function Reference: gdsc_to_bool_val
Summary
Check the boolean true or false.
Description
Checks a variable to see if it should be considered a boolean true or false.
Also takes into account some text-based representations of true of false,
such as ‘false’,’N’,’yes’,’on’,’off’, etc.
Parameters
- $in
- (mixed) (required) The variable to check.
- Default: None
- $strict
- (bool) (required) If set to false, consider everything that is not false to be true.
- Default: None
Return Values
- (bool)
- The boolean equivalent or null.
Change Log
Since: 1.0.0
Source File
gdsc_to_bool_val() is located in geodirectory-functions/shortcode_functions.php [Line: 100]
Source Code
function gdsc_to_bool_val($in, $strict = false)
{
$out = null;
// if not strict, we only have to check if something is false
if (in_array($in, array(
'false',
'False',
'FALSE',
'no',
'No',
'n',
'N',
'0',
'off',
'Off',
'OFF',
false,
0,
null
), true)) {
$out = false;
} else if ($strict) {
// if strict, check the equivalent true values
if (in_array($in, array(
'true',
'True',
'TRUE',
'yes',
'Yes',
'y',
'Y',
'1',
'on',
'On',
'ON',
true,
1
), true)) {
$out = true;
}
} else {
// not strict? let the regular php bool check figure it out (will
// largely default to true)
$out = ($in ? true : false);
}
return $out;
}