The function $cmp compares two values with each other and returns a truth value as result. A compare operator specifies how the values are compared with each other.
Tooltip
Syntax: $cmp(left,operator,right[,mode])
Parameter
Description
leftThe left comparison value.
operatorDefines the compare operator. The following operators are available:
= or == (equals)
!= (unequal to)
< (less than)
<= (less than or equal)
> (greater than)
>= (greater than or equal)
reg (regular expression)
rightThe right comparison value.
modeAn optional compare mode that specifies whether the comparison should be numeric or text-based.
The following modes are available:
i (integer)
n (numeric)
s (text based) → default, if nothing is specified
o (object based) → e.g. if two date values are to be compared
Returns true if the condition for the comparison 'left operator right' is fulfilled, otherwise false.
Example: $cmp(10,>,5) – Returns true, because 10 is greater than 5
Syntax
$cmp(left,operator,right[,mode])
Parameter
Name | Description |
|---|---|
left | The left comparison value. |
operator | Defines the compare operator. The following operators are available:
|
right | The right comparison value. |
mode | An optional compare mode that specifies whether the comparison should be numeric or text-based. The following modes are available:
|
Return value
Returns true if the condition for the comparison 'left operator right' is fulfilled, otherwise false.
Example
Syntax | Result | Remarks |
|---|---|---|
$cmp(2,>,11,n) | false | The number '2' is not greater than the number '11'. |
$cmp(2,>,11,s) | true | In a text-based comparison, '2' is greater than '11' because the ASCII character code of '2' is greater than that of '1'. |
$cmp(2,>,11) | true | Same reason as above. s is the default mode. |
$cmp(0,==,0) | true | |
$cmp(Hallo,==,Hallo) | true | |
$cmp(hallo,==,Hallo) | false | Case sensitive. |
$cmp(Hallo,reg,/^hallo$/i) | true | Regular case insensitive comparison. |