Reply to RE: [PHP] Comparison Operator

Your name:

Reply:


Posted by Mike Ford on 10/01/12 11:05

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@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

[Back to original 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

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