Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PHP, if 0==false is true, and false==false is true, how to test for false?

Tags:

php

preg-match

I am especially interested in testing the return value of preg_match, which can be 1, 0, or false.

like image 796
user698739 Avatar asked Nov 29 '22 18:11

user698739


2 Answers

$val === false;

Example:

0 === false; // returns false
false === false; // returns true

Use triple equals operator/strict comparison

like image 62
Mike Lewis Avatar answered Dec 05 '22 17:12

Mike Lewis


Use === type comparison. Check the manual: http://www.php.net/manual/en/language.operators.comparison.php

like image 38
Eliasdx Avatar answered Dec 05 '22 16:12

Eliasdx