It looks like you just need to save it in your database.
But if you cannot do this, draw it into some configuration file and save it in some kind of permanent object or just use a static variable:
function foo($key) { static $cache = array(1 => 'abc', 2 => 'def', 3 => 'ghi'); if (array_key_exists($key, $cache)) { return $cache[$key]; } else {
In the above example, $cache will exist only once. (If you knew that the values ββwould never be null , you can use isset instead of array_key_exists .)
This is not very flexible, though, because changing the data requires changing the code. Usually you want your data and your code to be separate from each other.
This may mean saving it in some kind of file (json, xml, php, whatever) and loading it into some structure that you create only once. You will then pass this object or array to where it was needed. (Or, if you want to be hacked, you can use a static class. I suggest against this, though.)
source share