Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 25, 2022 05:14 am GMT

How To Print & Write Array Values to Files in PHP

Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/php/how-to-print-write-array-values-to-files-in-php

In this post, I will share a short and simple code on how to print and write array values to files in PHP. If you have a task or problem that needs to write the array value to a file then this is for you. In this example, I'm using file_put_contents() to put the value to a file. And PHP_EOL to newline after loop the array values.

<?php$contents = '';$programmingLanguages = ['PHP', 'PYTHON', 'C#', 'C++'];foreach ($programmingLanguages as $programmingLanguage) {    $contents .= $programmingLanguage.PHP_EOL;}file_put_contents('filename.txt', $contents, true);?>

Thanks for reading. I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/php/how-to-print-write-array-values-to-files-in-php if you want to download this code.

Happy coding :)


Original Link: https://dev.to/codeanddeploy/how-to-print-write-array-values-to-files-in-php-105

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To