The to-bool operation converts the input value into a boolean (true or false). This is useful when you need a clear yes/no flag for conditions, routing, or API calls.
How it works
The following values are treated as false:
- false (already boolean false)
- 0 (integer zero)
- 0.0 (float zero)
- “” (empty string)
- “0” (string containing zero)
- [] (empty array)
- null
All other values are treated as true, including:
- Any non-zero number (positive or negative)
- Any non-empty string (even “false” or “0.0”)
- Any non-empty array
- Any object or resource
Examples
Input | Result |
---|---|
false | false |
true | true |
0 | false |
-1 | true |
0.0 | false |
“0” | false |
“false” | true |
“hello” | true |
[] | false |
[0] | true |
null | false |
Usage in PalDock
Use to-bool when you need to:
- Normalize form inputs (e.g., interpret checkbox-like fields as true/false).
- Guarantee a boolean value before a Condition or Router element.
- Send proper boolean values in API requests (true/false instead of text or numbers).
Best Practices
- Remember that the string “0” is the only non-empty string treated as false.
- The string “false” is considered true (because it is non-empty). If you need to handle “true”/”false” text literally, normalize the string first.
- Empty arrays are false; arrays with at least one item are true.