Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/laravel/how-to-print-write-array-values-to-files-in-laravel-8
Advanced Laravel SAAS Starter Kit with CRUD Generator - GET YOUR COPY NOW!
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);
Advanced Laravel SAAS Starter Kit with CRUD Generator - GET YOUR COPY NOW!
I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/how-to-print-write-array-values-to-files-in-laravel-8 if you want to download this code.
Happy coding :)
Top comments (0)