05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Table 2-7. Type of comparision performed by the comparision operators<br />

First operand Second operand Comparison<br />

Number Number Numeric<br />

String that is entirely numeric String that is entirely numeric Numeric<br />

String that is entirely numeric Number Numeric<br />

String that is not entirely numeric Number Lexicographic<br />

String that is entirely numeric String that is not entirely numeric Lexicographic<br />

String that is not entirely numeric String that is not entirely numeric Lexicographic<br />

One important thing to note is that two numeric strings are compared as if they were<br />

numbers. If you have two strings that consist entirely of numeric characters and you<br />

need to compare them lexicographically, use the strcmp( ) function.<br />

The comparison operators are:<br />

Equality (==)<br />

If both operands are equal, this operator returns true; otherwise, it returns false.<br />

Identical (===)<br />

If both operands are equal and are of the same type, this operator returns true;<br />

otherwise, it returns false. Note that this operator does not do implicit type<br />

casting. This operator is useful when you don’t know if the values you’re comparing<br />

are of the same type. Simple comparison may involve value conversion.<br />

For instance, the strings "0.0" and "0" are not equal. The == operator says they<br />

are, but === says they are not.<br />

Inequality (!= or )<br />

If both operands are not equal, this operator returns true; otherwise, it returns<br />

false.<br />

Not identical (!==)<br />

If both operands are not equal, or they are not of the same type, this operator<br />

returns true; otherwise, it returns false.<br />

Greater than (>)<br />

If the lefthand operator is greater than the righthand operator, this operator<br />

returns true; otherwise, it returns false.<br />

Greater than or equal to (>=)<br />

If the lefthand operator is greater than or equal to the righthand operator, this<br />

operator returns true; otherwise, it returns false.<br />

Less than (

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!