Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Logical conjunction (&&)

Both operands must be truthy for the result to be true.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$first && $second

Both operands must be truthy for the result to be true. When the first is false-like, PHP skips the second. This allows an existence check to guard the subsequent read of a numeric field. The symbolic operator binds more tightly than assignment.

$first && $second

[false,true]

Examples

<?php
$row = [];
$safe = isset($row['qty']) && $row['qty'] > 0;
$row['qty'] = 3;
echo json_encode([$safe, isset($row['qty']) && $row['qty'] > 0]);

Result

[false,true]

Sources