Strange If

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Behzad
Forum Commoner
Posts: 28
Joined: Mon Jul 09, 2007 3:24 pm
Location: Tehran, Iran
Contact:

Strange If

Post by Behzad »

Why the result of the following "if-statement" is true?

Code: Select all

<?php

$x = 0;
if ($x == "salam") echo "Oops!";
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

When you compare a number with a non-number, php converts the latter and does numeric comparison.
Check Types/Type juggling and Operators/Comparison chapters in the manual.
Post Reply