Jump to content

Write Array to file


The Little Guy

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.