PHP : Replacing logical operators with logical strings with Example

In PHP normally we use logical operators for validating. The operators performs operation with values and return Boolean value as TRUE or FALSE.
Normal logical operators are AND(&&) and OR(||). We can able to replace logical operators with logical strings.

Logical string and :
We can replace logical operator "&&" with "and". This string also working same as of Logical AND operation.

Example:

$num = 0;
$testArray = array(1, 2, 3,);
if ($num and is_array($testArray)) {
  print "True";
}
else {
  print "False";
}
// Output
False

Logical string or :
We can replace logical operator "||" with "or". This string also working same as of Logical OR operation.

Example:

$num = 0;
$testArray = array(1, 2, 3,);
if ($num or is_array($testArray)) {
  print "True";
}
else {
  print "False";
}
// Output
True
Category: