You are here: Re: Simplifying a basic if statement conditional « PHP Programming Language « IT news, forums, messages
Re: Simplifying a basic if statement conditional

Posted by Edward Z. Yang on 05/19/07 18:23

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ciaran wrote:
> All great ideas guys! Thanks for the replies on this. I especially
> like purcaholic's one! Anyone know which of these methods would be the
> fastest? Are any of them actually any faster than the basic one I
> posted at the start?

Purcaholic's one doesn't work (as it stands: he probably mean to use
strpos) and is probably the slowest.

In terms of speed, it's probably like this (from fastest to slowest):

1. Original method
2. isset($lookup[$var])
3. in_array
4. strstr

If you have a particularly large set of numbers to compare against,
method 2 may end up being faster due to the implementation of
associative arrays needing only a binary search. I would use method 2
simply because it's more maintainable (you can generate the $lookup
array from anywhere you want).

But I should warn you: this is really premature optimization and will
make no difference at all most of the time.

- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org> Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGT0CzqTO+fYacSNoRAt6ZAJ9stC/G1vPm0orjhfegDK6vRvsQhwCeNz9V
iwhkovqnMTPpNIzUXH9Ff9I=
=Qajq
-----END PGP SIGNATURE-----

 

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

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