Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Difference in type or value (!==)

Distinguish a search result from its failure marker. Strict inequality with false accepts a valid zero result as well.

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

Syntax

$left !== $right

Distinguish a search result from its failure marker. Strict inequality with false accepts a valid zero result as well.

Scalar types are preserved. An integer and a string containing its digits are different. This lets a search result distinguish index zero from the boolean value false.

  • 0 !== false → true
  • 4 !== 4.0 → true
  • null !== null → false
  • array_search('A', ['A'], true) !== false → true

Examples

<?php
echo json_encode(0 !== false), PHP_EOL;
echo json_encode(4 !== 4.0), PHP_EOL;
echo json_encode(null !== null), PHP_EOL;
echo json_encode(array_search('A', ['A'], true) !== false), PHP_EOL;

Result

true
true
false
true

Sources