Table of contents
In my previous post, I shared how to print and write array values in PHP now we will do it with Laravel 8 using the File class provided by Laravel. In this example, we have an animal's array of values. We will loop it and we are using PHP_EOL to new line each result and append it to a variable $contents.
Â
$contents = '';
$animals = ['Cat', 'Dog', 'Carabao', 'Horse'];
foreach ($animals as $animal) {
$contents .= $animal.PHP_EOL;
}
File::put('filename.txt', $contents, true);
Â
I hope it helps. Thank you for reading :)
Read next