You are here: Re: [PHP] Comparison Operator « PHP « IT news, forums, messages
Re: [PHP] Comparison Operator

Posted by tg-php on 10/01/85 11:05

Ahh.. the trick question. hah.. Ok, let me see if I remember this (although it doesn't seem to follow the logic in my head.. I know someone else will explain it better but let me take a crack at it):

When comparing a two different variable types that PHP thinks it knows how to compare, it will try. In this case, I believe the 'A' gets converted to a true/false type thing (0 or 1).. although I thought it'd convert to a 1 so you'd have if (1 == 0) which would be false.

At any rate, something like that is happening and it's comparing values that you don't think you're comparing.

Try using the triple equal sign operator (===) instead of the dobule (==). This forces PHP to not do the conversion.. to compare EXACT values. Using === means that 0 does not equal '0' because 0 is an int and '0' is a string.

Someone else will give a better explaination soon, just wanted to give you something so you weren't stuck/frustrated/etc for too long.

-TG

= = = Original message = = =

Could anyone tell me why this code echos?

<?php
$value = 0;
$curval = 'A';
if ($value == $curval)
echo "WTH, Over<br>";

?>


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация