BrainPill Posted December 26, 2018 Share Posted December 26, 2018 (edited) I would like to write the values of an array to a php file. I use fopen/fwrite/fclose to write the php file. I can define the array like this: Quote $fruit = array('apples','bananas','grapes'); But I get an array to string conversion error when the file is created. <?php $pagename = 'testpage2018a'; $data = 'abcd987654'; $fruit = array('apples','bananas','grapes'); $var5 = '$data'; $var6 = '$fruit'; $fopenvar = fopen('F:/www/yourdirectory/test/'.$pagename.'.php', 'w'); $page_cont = " <html> <body><center> <?php $var5 = '" . $data . "'; var_dump($var5); $var6 = '" . $fruit . "'; var_dump($var6); ?> </center> </body> </html> ?> How to solve this and write an array to a php file? Edited December 26, 2018 by BrainPill Link to comment Share on other sites More sharing options...
justsomeguy Posted December 31, 2018 Share Posted December 31, 2018 What exactly do you think will happen there? You're trying to use an array in a string context, so it is automatically converting the array to a string. What do you expect it to do there? Link to comment Share on other sites More sharing options...
BrainPill Posted January 3, 2019 Author Share Posted January 3, 2019 I meanwhile solved this by using var_export(). The output then is an exact render of the array in php. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now