Sort array from .dat file

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm using the following to open and print values from a .dat file but
I can't figure out how to sort the results. I think I need to use
either the array_multisort() or krsort() functions. If so, how would I
do that?


$fp = fopen("datfile.dat", r);
$count = 0;
   $register = fgets($fp, 4);
   $sales = fgets($fp, 5);

   $register_array[$count] = $register;
   $sales_array[$count] = $sales;

   print "Register:  $register_array[$count]<br>";
   print "Sales:     $sales_array[$count]<br>";
   $count = $count + 1;



Re: Sort array from .dat file

Dan R. wrote:
Quoted text here. Click to load it

No matter which function you use, you will have to create the array before  
you can apply it. Immediately, performance will be an issue when files get  

The best thing in this case (besides using a database) is to sort the data  
while writing to the file. Performance will then be less of an issue, since  
you could make the process asynchrone. When the file is already sorted, all  
you have to do is displaying its contents.


Site Timeline