$config = parse_ini_file('config.ini'); // retrieves all settings from config file $dbHost = getSetting('db_host', $config); // retrieves the value for db_host from the config $dbUser = getSetting('db_user', $config); // retrieves the value for db_user from the config $dbPass = getSetting('db_pass', $config); // retrieves the value for db_pass from the config
$config = file_get_contents('settings.json'); // retrieves all settings from JSON file $configArr = json_decode($config, true); // converts JSON to associative array $siteName = getSetting('site_name', $configArr); // retrieves the value for site_name from the config $siteEmail = getSetting('site_email', $configArr); // retrieves the value for site_email from the configThis example shows how to use the getSetting method to retrieve specific site settings from a JSON file. The method is called twice with different settings names to retrieve their corresponding values from the parsed JSON file. Package library: There might be packages like symfony or Laravel which have their own implementation of getSetting thereby easing the process of accessing config files.