The Little Guy Posted August 11, 2011 Share Posted August 11, 2011 I have an array, and I would like to write it to a php file for later use. Any suggestions on how I could write the array to file? Here is an example array. When the array gets modified in my code, I want to have a method that saves it to a file when I call it. Any suggestions of how can I save it into a file? $arr = array( "opt1" => 1, "opt2" => array( "opt2.1", "opt2.2" ), "opt3" => array( "opt3.1", "opt3.2", "opt3.3" ) ); Link to comment https://forums.phpfreaks.com/topic/244523-write-array-to-file/ Share on other sites More sharing options...
The Little Guy Posted August 11, 2011 Author Share Posted August 11, 2011 Never mind, I got it. public function update_settings(){ file_put_contents("$this->pluginLocation/databases/settings.txt", serialize($this->settings)); } public function get_settings(){ $this->settings = unserialize(file_get_contents("$this->pluginLocation/databases/settings.txt")); } Link to comment https://forums.phpfreaks.com/topic/244523-write-array-to-file/#findComment-1256002 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.