Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Save an array from form to array in a file

Hi! I want to save my form submissions in an array using the $_POST variable. The array is kind of stored there but only for a session, I want it to be stored in that array forever. How do I do this? I looked at "file_put_contents" but that makes my .php file useless ass I can't use any variables or something, because it seems to be just a .txt instead of a .php. Even though it is stored as a .php.

Anyone?

1 Answer

Hi Joakim,

If you don want to use a database you have 2 options:

You can save the data in a json file with json_encode / json_decode.

or

You can save it in a text file

file_put_contents($filename, '<?php $arr = ' . var_export($arr, true) . ';');