What role does the file_put_contents() function play in writing data from an array to a .ini file in PHP?

The file_put_contents() function in PHP is used to write data to a file. To write data from an array to a .ini file, we can first convert the array to a string using the http_build_query() function, and then write this string to the .ini file using the file_put_contents() function.

// Sample array data
$data = array(
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3'
);

// Convert array to string
$ini_string = http_build_query($data);

// Write string to .ini file
file_put_contents('data.ini', $ini_string);