RE: Comparison Operator

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

 



To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm



On 10 January 2005 21:20, Chadwick, Russell wrote:

> The function this is from sometimes uses $_POST or $_GET input, so
> sometimes its comparing 1337 with '1337' and === would break that.
> 
> so I'll have to use something like:
> 
> if (($value == $curval) && !(is_string ($curval) && ($value == 0)))

I would cast both sides of the comparison to the same type and then use the
identity operator.  So, depending on exactly what kind of comparison you
want (and maybe how safe your data are!), either of:

   if ((int)$value === (int)$curval)

   if (string)$value === (string)$curval)

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

-- 
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