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