Skip to the content
Documentation

and

No ratings yet

Summary

Evaluates all parameters to check if any are evaluated as FALSE

Usage

and( value1 [, value2 [, ... ] ] )

Parameters

Name Type Description Required
value1 any A variable/value to be evaluated. Yes.
value2 any Another variable/value to be evaluated. No.

Returns

One of the parameters or TRUE (see below).

Description

This operator evaluates all parameters.
When one of them is found to be FALSE, the operator will then return that parameter. Under some circumstances shortcutting is then applied, which means that once a parameter in found to be FALSE, the evaluation of the rest of the parameters stops. However this is not always the case, and depends on personal settings.
If none of the parameters are found to be FALSE, the operator will return TRUE.

The following table shows how the different types are evaluated by this operator.

Type Evaluation
Number TRUE if the value is non-zero, FALSE otherwise.
String TRUE if the string consists of at least one character, FALSE otherwise.
Boolean TRUE if the boolean is a TRUE value, FALSE is otherwise.
Array TRUE if the array has one or more elements, FALSE otherwise.
Object TRUE if the object provides the "attributes" and the "attribute" methods, FALSE otherwise.
NULL Always FALSE.
Other Other types will be evaluated in the same way as PHP would do.

Examples

Example 1

{if and( false(), true(), false() )}
    The truth is out there.
{else}
    The day the earth stood still.
{/if}

The following output will be produced: "The day the earth stood still.".

Example 2

{def $a=array()
     $b=array( 1, 2, 3 )
     $c=array( 4, 5, 6 )}

{and( $a, $b, $c )}

The code above will return the empty array that is represented by $a.

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.