Re: IF command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Oct 18, 2007, at 9:50 PM, Bastien Koert wrote:



Are you sure that the value is a string? If its numeric, then try the check without the quotes around the value


http://www.php.net/manual/en/language.operators.comparison.php
"If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers."

<?php

$component_reference = 5;
if ( ($component_reference != "5") AND ($component_reference != "19") ) {
	echo("I am not a 5 or a 19<br>");
}
else
	echo("I am a 5 or a 19<br>");


$component_reference = "5";
if ( ($component_reference != "5") AND ($component_reference != "19") ) {
	echo("I am not a 5 or a 19<br>");
}
else
	echo("I am a 5 or a 19<br>");

$component_reference = 3;
if ( ($component_reference != "5") AND ($component_reference != "19") ) {
	echo("I am not a 5 or a 19<br>");
}
else
	echo("I am a 5 or a 19<br>");

$component_reference = "3";
if ( ($component_reference != "5") AND ($component_reference != "19") ) {
	echo("I am not a 5 or a 19<br>");
}
else
	echo("I am a 5 or a 19<br>");

?>



The results:

I am a 5 or a 19
I am a 5 or a 19
I am not a 5 or a 19
I am not a 5 or a 19

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux