From the PHP manual:
Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus:
'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
Hence before diving into your code further:
-
It would need much more than
$arr_name = str_replace(' ','_',get_the_title());
to make this fail-safe. Currently, your code is bound to fail as soon as the page title contains any non-alphanumeric characters. -
Because of the above, among other reasons, I’d strongly suggest you reconsider the general architectural approach. Ask yourself this: Why would you need variable variable in the first place? (I don’t see a reason and I doubt this to be the most viable solution, even if a valid reason exists.)