Reply to Re: Simplifying a basic if statement conditional

Your name:

Reply:


Posted by gosha bine on 05/21/07 08:39

On 19.05.2007 16:18 Schraalhans Keukenmeester wrote:
> At Sat, 19 May 2007 14:52:28 +0200, gosha bine let his monkeys type:
>
>> Ciaran wrote:
>>> Is there a more efficient way to write this:
>>> if($var=1 || $var=4 || $var=27 || $var=28 || $var=30 || $var=37 ||
>>> $var=38){echo "true";}
>>>
>>> Cheers,
>>> Ciarán
>>>
>> ='s should be == I guess
>>
>> if(in_array($var, array(1, 4 etc)))
>>
>> is perhaps shorter, but not "more efficient", so the answer is "no".
>
> If by 'more efficient' you mean 'executing faster', the answer is:
> It depends on array length.
> For short arrays in_array is slower, for long arrays it appears to be
> faster. (function call overhead becomes less of a factor I suppose)
>
> Sh.
>

'more efficient' means 'runs faster' and 'uses less memory'. I think
'or' code will win in both categories.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

[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

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