I’m trying to write a php function that takes the $name and $time and write it to a txt file (no mySQL) and sort the file numerically.
For example:
10.2342 bob
11.3848 CandyBoy
11.3859 Minsi
12.2001 dj
just added Minsi under a faster time, for example.
If the $name already exists in the file, only rewrite it if the time is faster (smaller) than the previous one, and only write if the time fits within 300 entries to keep the file small.
My forte isn’t file writing but I was guessing to go about using the file() to turn the whole file into an array, but to my avail, it didn’t work quite like I wanted. Any help would be appreciated
If your data sets are small, you may consider using
var_export()Perform your sorts using the PHP
array_*functions, and dump when necessary.var_export()saves the data as PHP parsable text, which is why thedump()function prepends the string<?php return. Of course, this is really only a viable option when your data sets are going to be small enough that keeping their contents in memory is not unreasonable.