Data: $data = array('Alice', 'Bob', 'Carol', 'David', 'Elizabeth', 'Frank');
Method A:
file_put_contents('filename.ext', implode("\n", $data) );
Method 2:
$fp = fopen('filename.ext', 'w'); foreach($data as $name) { fwrite($fp, $name . "\n"); } fclose($fp);
Does one method have any significant penalties over the other?
Any significantly faster speed, even at a cost? at no cost?
Preferences? Is it situational? Which would you use in production code vs 1-use throwaway scripts?
Note: Please ignore any issues of checking to see if the filename is writable, or filepointer is !false. assume 0 friction, and everything just "works".