Last active
September 16, 2015 21:30
-
-
Save Terrance/58bfc2cc31af986f533c to your computer and use it in GitHub Desktop.
An importable script to hold sensitive information not to be committed in other files. Provides string value lookup with keys, or categorised sub-keys.
This file contains hidden or 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
<?php | |
/* | |
The keystore is a map from keys to values, but nested arrays allow sub-key organisation. | |
This means an array cannot be retrieved as a value, only its (scalar) contents. | |
*/ | |
$keystore = array( | |
"key" => "valueA", | |
"group" => array( | |
"subkey1" => 42, | |
"subkey2" => true | |
) | |
); | |
/* | |
Call with a list of keys to traverse, and returns the value. | |
e.g. keystore("key") => "valueA" | |
keystore("group", "subkey1") => 42 | |
keystore("group", "subkey2") => true | |
keystore("group") => false | |
*/ | |
function keystore() { | |
global $keystore; | |
$out = $keystore; | |
foreach (func_get_args() as $arg) { | |
if (!array_key_exists($arg, $out)) { | |
return false; | |
} | |
$out = $out[$arg]; | |
} | |
return is_scalar($out) ? $out : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment