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
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
  }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.