Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Apr 292010
 

Strict comparison in PHP

Answer:

PHP has two ways to compare two variables, type-safe and type-less, e.g.

Type-safe

print ( "123" === "123" ); // print 1
print ( 123 === 123 ); // print 1
print ( 123 === "123" ); // print nothing

Type-less

print ( "123" == "123" ); // print 1
print ( 123 == 123 ); // print 1
print ( 123 == "123" ); // print 1

Reference: http://php.net/manual/en/language.operators.comparison.php

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>