// Define the configuration settings as an array $config = [ 'db_host' => 'localhost', 'db_user' => 'username', 'db_password' => 'password' ]; // Save the configuration to a file file_put_contents('config.ini', serialize($config)); // Load the configuration from the file $config = unserialize(file_get_contents('config.ini')); // Access the configuration settings echo $config['db_host']; // Output: localhost
// Load the configuration file as a PHP array $config = parse_ini_file('config.ini'); // Access the configuration settings echo $config['db_host']; // Output: localhostIn this example, we load the configuration file using the `parse_ini_file` function, which returns an array representing the configuration. We then access the `db_host` setting using array notation. This code does not use any particular library or package either, but it relies on a built-in PHP function to parse INI files. Other common file formats used for configuration files include JSON and YAML, which can be parsed using dedicated packages or functions.