Skip to content

Instantly share code, notes, and snippets.

@ronakjain2012
Created January 25, 2019 05:45
Show Gist options
  • Save ronakjain2012/edef99a0960fcfaf13b13677d6f0c902 to your computer and use it in GitHub Desktop.
Save ronakjain2012/edef99a0960fcfaf13b13677d6f0c902 to your computer and use it in GitHub Desktop.
Config Function like laravel
function config($key, $default =null) {
$file = strtok($key,'.');
$folderPath = __DIR__ . '\\..\\..\\config\\'.$file.'.php';
$value = $default;
try {
$value = require($folderPath);
$keys = strtok('.');
} catch (\Exception $e) {
return $default;
}
if(!empty($file)) {
while($keys!==false) {
if(!isset($value[$keys])) {
return $default;
} else {
$value = $value[$keys];
}
$keys = strtok('.');
}
unset($file,$folderPath);
return $value;
} else {
return $default;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment