I have two static hashtables in my program:
public static $labels = [
'id' => 'ID',
'name' => 'Name',
'email' => 'E-mail',
'password' => 'Password',
];
public static $columnTypes = [
'id' => 'number',
'name' => 'text',
'email' => 'text',
'password' => 'text',
];
First is for the labels of the database columns and the second for each type (necessary for filtering).
My problem is that I often need to get the type of a column by its label what leads to speed issues (hashtables are pretty slow in this direction right?).
My approaches would be the following:
- Type a hashtable
label => type
which is bad because I have to repeat myself and there is no support for other languages - Create the
label => type
hashtable in a static content on runtime (is this possible in php?)
Are there better approaches or best practices for this issue and is the second approach possible in php? (maybe with a small example ;)