/    Sign up×
Community /Pin to ProfileBookmark

[code]
$filename = “refs.txt”;
$lines = array();
$file = fopen($filename, “r”);
while(!feof($file)) {

//read file line by line into a new array element
$lines[] = fgets($file, 4096);

}
fclose ($file);

$result = array_reverse($lines);
echo “<BR><br> $lines[0] <br> $lines[1] <BR> $lines[2] <BR> $lines[3] <BR> $lines[4] <BR> $lines[5]”;

[/code]

ok the last line shows the fisrt 5 lines of my text file i need to reverse it to show the last lines i looked at array_Reverse but it just confuseed me?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehMar 13.2006 — [code=php]foreach(array_reverse(file('./refs.txt')) as $key => $line)
{
echo '<br>'.$line;
if($key == 4) break;
}[/code]
Copy linkTweet thisAlerts:
@Brooksie155Mar 14.2006 — if you had made the line

[COLOR=Blue]$result[/COLOR] [COLOR=Green]=[/COLOR] [COLOR=Blue]array_reverse[/COLOR][COLOR=Green]([/COLOR][COLOR=Blue]$lines[/COLOR][COLOR=Green]);[/COLOR]

so it read

[COLOR=Blue]$lines[/COLOR][COLOR=Green] = [/COLOR] [COLOR=Blue]array_reverse[/COLOR][COLOR=Green]([/COLOR][COLOR=Blue]$lines[/COLOR][COLOR=Green]);[/COLOR]

It would probably of worked, possibly worth remebering if you need to reference the array again later.

N.B. didn't actually look this up so I may be wrong, but logically it makes sense to me.
×

Success!

Help @putnamehere spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...