Is this the most efficient way to get and remove first line in file?

I came up with this idea yesterday:

function read_and_delete_first_line($filename) {
  $file = file($filename);
  $output = $file[0];
  unset($file[0]);
  file_put_contents($filename, $file);
  return $output;
}

Leave a Comment