So you essentially have a database; id is the key field and name is an attribute field. Given an id value, you want to extract an attribute field from the corresponding database record. You're asking if it is better to have an array that explicitly models the database, or construct the database implicitly within your executable code.
In my opinion the most important measures of which approach is better are the following. The amount of space consumed is not very important.
- easiest to understand
- easiest to implement
- easiest to maintain
- most robust (hardest to break)
In my opinion an explicit database wins in every category.
By the way, I don't think the code you provided will work; but that doesn't change my conclusion.