You are here: Re: Generate all possibilities « PHP Programming Language « IT news, forums, messages
Re: Generate all possibilities

Posted by Koncept on 10/10/06 08:28

In article <PU3Ug.2834$xt3.194@newsfe07.lga>, Bob Stearns
<rstearns1241@charter.net> wrote:

> for($i1=0; $i1<strlen($scope); $i1++) {
> $key = substr($scope, $i1, 1);
> print $key;
> for($i2=0; $i2<strlen($scope); $i2++) {
> $key = substr($key,0,1) . substr($scope, $i2, 1);
> print $key;
> for($i3=0; $i3<strlen(scope); $i++) {
> $key = substr($key,0,2) . substr($scope, $i3, 1);
> print $key;
> }
> }
> }

This script is *much* slower than it has to be. In every loop
iteration, strlen is being recalculated. You could simply assign $len
to strlen($scope) and reference $len through your example to save some
processing time.

$len = strlen( $scope );
for( $i1 = 0; $i1 < $len; $x++ ) {
// stuff ..
}

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche

 

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

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