Jump to content

sort through an array problem


seadonkey

Recommended Posts

What I  am working on is making a guest book to where I write the valuables(name/last/email) to the guest list if it does not exist yet. My problem is with getting the information into the guest book to write.

 

For the sort, instead of using fopen and fgets, use file() to read the whole file into an array, say $GuestBookArray. Then you can sort

by saying sort($GuestBookArray);

 

Then use a for loop to loop through the array and print the elements.

 

As a noobie I am trying to figure out how to understand the file function and how to do this.

it should be file(filename[, use_include_path]) so for this part would it look like file(guestbook.txt. , "a"[, use_include_path]) (would the include path be the $GuestBookArray?

 

Then the loop part is tossing me for a loop. ???

 

Any suggestions would be great

 

Link to comment
https://forums.phpfreaks.com/topic/95864-sort-through-an-array-problem/
Share on other sites

file() will not let you write into a file, it is purely for reading. you will have to use fopen/fwrite

 

update: you can use file to read from the guestbook though:

<?php
  foreach(file('guestbook.txt') as $line){
    //do stuff to $line
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.