deko wrote:[color=blue]
>
> "deko" <nospam@hotmail.com> wrote in message
> news:jl4Lc.12768$wa1.81@newssvr25.news.prodigy.com ...[color=green][color=darkred]
>> > >I see. But I'm still curious how it's more efficeint to start at the[/color]
>> last[color=darkred]
>> > >element in the array.
>> > Because that is how your file is ordered.[/color]
>>
>> The file is ordered:
>>
>> oldest
>> newest
>>
>> Here is the complete code:
>>
>> $avs = file($viscounter);
>> for( $i=count($avs)-1; $i>=0; $i-- )
>> {
>> if( $avs[$i] > TIME24h )
>> {
>> ++$v24h;
>> }
>> if( $avs[$i] > TIME30d )
>> {
>> ++$v30d;
>> }
>> if( $avs[$i] > TIME365d )
>> {
>> ++$v365d;
>> }
>> if( $avs[$i] < TIME365d )
>> {
>> echo "<br>There are old entries.";
>> break;
>> }
>> }
>>
>> It's more efficient to start at the last element of the $avs array - which
>> is the newest entry - because of the way the if statements are sequenced -
>> is this correct?
>>
>> Okay, what if I reversed the order of the if statements?
>> Would I then use this:
>>
>> $c=count($avs)
>> for( $i = 0; $i = $c; $i++ )
>>[/color]
>
> I meant: for( $i = 0; $i < $c; $i++ )[/color]
No.
Let's say you have a file with 1, 2, 3, 4, 5, 6, 7, 8, 9 each on its
line and you want to output the values > 5
if you start at the top [ for($i=0; $i<8; ++$i) ] you do:
compare 1 with 5 -- !>; continue;
compare 2 with 5 -- !>; continue;
compare 3 with 5 -- !>; continue;
compare 4 with 5 -- !>; continue;
compare 5 with 5 -- !>; continue;
compare 6 with 5 -- >; print and continue;
compare 7 with 5 -- >; print and continue;
compare 8 with 5 -- >; print and continue;
compare 9 with 5 -- >; print and continue;
If you start at the bottom [ for($i=8; $i>=0; --$i) ] you do:
compare 9 with 5 -- >; print and continue;
compare 8 with 5 -- >; print and continue;
compare 7 with 5 -- >; print and continue;
compare 6 with 5 -- >; print and continue;
compare 5 with 5 -- !>; break;
This way you will not compare 4, 3, 2, or 1!
If there are a large number of records you want to ignore, savings are
enormous!
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |