Created
January 25, 2019 05:45
-
-
Save ronakjain2012/edef99a0960fcfaf13b13677d6f0c902 to your computer and use it in GitHub Desktop.
Config Function like laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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