lundi 18 janvier 2016

PHP get random line from CSV without loop

I have multiple big CSV files with more than 1 million lines. I can't change that.

I need in a loop, get a random line of a random CSV file and output this line.

For now I have :

        for ($i=0; $i < 50; $i++) {
            $randomFile = $files[array_rand($files)];

            if (($handle = fopen($randomFile, "r")) !== FALSE) {
                //HERE I NEED TO GET A RANDOM LINE OF $handle FILE
            }
        }

How can I get a random line of my CSV $handle, without loop like all solution I see everywhere ?

I already tried loop solution but my CSv files are too big and my script freeze each time.

Thanks !




Aucun commentaire:

Enregistrer un commentaire