Sort array from .dat file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan R.

    Sort array from .dat file

    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?

    <html>
    <body>
    <pre>
    <?php

    $fp = fopen("datfile. dat", r);
    $count = 0;
    while(!feof($fp ))
    {
    $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;
    }

    ?>
    </pre>
    </body>
    </html>

    --
    Thanks,
    Dan

  • Janwillem Borleffs

    #2
    Re: Sort array from .dat file

    Dan R. wrote:
    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?
    >
    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
    bigger.

    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.


    JW


    Comment

    Working...